Here is the use of MVC three injection points: Idependencyresolver for Injection
The Global.asax code in the global class is as follows:
#region MVC Inject System.Web.Mvc.DependencyResolver.SetResolver (new DaHua.Sites.DependencyResolve (DaHua.Common.Runtime.EngineContext.Current, System.Web.Mvc.DependencyResolver.Current)); #endregion
Implementation class:
/// <summary> ///MVC injection Point/// </summary> Public classDependencyresolve:idependencyresolver {#regionFieldsPrivateIengine _engine;//Container engine PrivateIdependencyresolver _innerresolver;//internal dependency parsing interface #endregion #region. ctor PublicDependencyresolve (Iengine engine, Idependencyresolver innerresolver) { This. _engine =engine; This. _innerresolver =Innerresolver; } #endregion #regionMethods Public ObjectGetService (Type servicetype) {varService =_engine. Tryresolve (servicetype); if(Service = =NULL) {Service=_innerresolver.getservice (servicetype); } returnService; } Publicienumerable<Object>getservices (Type servicetype) {varServices =_engine. ResolveAll (servicetype); if(Services = =NULL) {Services=_innerresolver.getservices (servicetype); } returnservices; } #endregion }
Well, to this the main, the entire process is injected, can be in the Controller's constructor to obtain services can also take advantage of Tryresolve to obtain services.