What I learned from Pro ASP 4 book
Open source of ASP.
Http://www.opensource.org/licenses/ms-pl.html
1. Introduce new trends of web development
node. js, Ruby on Rails,
2. Ninject
1) Ninject is used to de-couple classed, which known as DI dependency Inject. It is a DI container.
2) Adding Ninject to the Visual Studio Project
Open nuget->online-> Search for Ninject
3) How to use Ninject to implement DI
Implement Resolver
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSYSTEM.WEB.MVC;5 usingNinject;6 usingninject.parameters;7 usingNinject.syntax;8 usingSystem.Configuration;9 usingEssentialtools.models;Ten One namespaceessentialtools.infrastructure A { - Public classNinjectdependencyresolver:idependencyresolver - { the PrivateIkernel kernel; - - PublicNinjectdependencyresolver () - { +Kernel =NewStandardkernel (); - addbindings (); + } A at Public ObjectGetService (Type servicetype) - { - returnkernel. Tryget (servicetype); - } - - Publicienumerable<Object>getservices (Type servicetype) in { - returnkernel. GetAll (servicetype); to } + - Private voidaddbindings () the { *Kernel. Bind<ivaluecalculator> (). To<linqvaluecalculator>(); $ //Create binding with property valuePanax NotoginsengKernel. Bind<idiscounthelper> (). To<defaultdiscounthelper> (). Withpropertyvalue ("discountsize", 50m); - the //Binding When specific condition happened +Kernel. Bind<idiscounthelper> (). To<flexiblediscounthelper>() A. Wheninjectedinto<linqvaluecalculator>(); the } + } -}
View Code
Inject Resolver into Global.asax
protected void Application_Start () { arearegistration.registerallareas (); Dependencyresolver.setresolver (new ninjectdependencyresolver ()); Webapiconfig.register (globalconfiguration.configuration); Filterconfig.registerglobalfilters (globalfilters.filters); Routeconfig.registerroutes (routetable.routes); }
View Code
Use DI Relationship in Controller
Private ivaluecalculator Calc; // // GET:/home/ Public HomeController (ivaluecalculator calcparam) { = calcparam; }
View Code
3. Moq
It is a DLL used to unit testing
Pro ASP. NET MVC 4, 4th edition Reading Note---part (1) DI