Difference between revisions of "StructureMap Implementation"

From Logic Wiki
Jump to: navigation, search
(Created page with "Category:MVC Category:CSharp * Get Structuremap package from NuGet * Get Servicelocation package from NuGet * Create folder DependencyInjection for Ioc Classes * Copy...")
 
Line 5: Line 5:
 
* Get Servicelocation package from NuGet
 
* Get Servicelocation package from NuGet
 
* Create folder DependencyInjection for Ioc Classes
 
* Create folder DependencyInjection for Ioc Classes
−
* Copy the classes from old project ( [DependencyScope:DependencyScope] DependencyScope , DependencyResolver)
+
* Copy the classes from old project ( [[DependencyScope]], [[DependencyResolver]])
 
* Copy DependencyScope and DependencyResolver into the folder ‘DependencyInjection‘
 
* Copy DependencyScope and DependencyResolver into the folder ‘DependencyInjection‘
 
* Resolve classes names
 
* Resolve classes names
Line 11: Line 11:
 
** System.Web.Http
 
** System.Web.Http
 
** System.Web.Http.WebHost
 
** System.Web.Http.WebHost
−
* Create IocConfig (copy code from the old project)
+
* Create [[IocConfig]] (copy code from the old project)
 
* Resolve Dependencies
 
* Resolve Dependencies
 
* Add IocConfig call to Global.asax.cs (reference newly created DependencyResolver Class)
 
* Add IocConfig call to Global.asax.cs (reference newly created DependencyResolver Class)
 +
<pre>
 +
      protected void Application_Start()
 +
        {
 +
            var container = IocConfig.Setup();
 +
            System.Web.Mvc.DependencyResolver.SetResolver(new DependencyResolver(container));
 +
            GlobalConfiguration.Configuration.DependencyResolver = new DependencyResolver(container);
 +
</pre>
 
* Different configurations for API project
 
* Different configurations for API project
 
* For API project you may not need this statement
 
* For API project you may not need this statement

Revision as of 14:01, 12 October 2016


  • Get Structuremap package from NuGet
  • Get Servicelocation package from NuGet
  • Create folder DependencyInjection for Ioc Classes
  • Copy the classes from old project ( DependencyScope, DependencyResolver)
  • Copy DependencyScope and DependencyResolver into the folder ‘DependencyInjection‘
  • Resolve classes names
  • To resolve interface IDependencyScope Add references to
    • System.Web.Http
    • System.Web.Http.WebHost
  • Create IocConfig (copy code from the old project)
  • Resolve Dependencies
  • Add IocConfig call to Global.asax.cs (reference newly created DependencyResolver Class)
       protected void Application_Start()
        {
            var container = IocConfig.Setup();
            System.Web.Mvc.DependencyResolver.SetResolver(new DependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new DependencyResolver(container);
  • Different configurations for API project
  • For API project you may not need this statement

System.Web.Mvc.DependencyResolver.SetResolver(new DependencyInjection.DependencyResolver(container));

  • For static methods concrete object can be get using the similar statement given below

var storeService = IocConfig.Setup().GetInstance<IUserStoreService<ApplicationUser>>();