Asp.net 5 web api dependency resolver -


i have created project asp.net 5 web api template. startup.cs file content this.

public class startup {     public startup(ihostingenvironment env)     {     }      public void configureservices(iservicecollection services)     {         services.addmvc();     }      public void configure(iapplicationbuilder app, ihostingenvironment env)     {         app.usestaticfiles();          app.usemvc();     } } 

i want use ioc framework autofac, structuremap , ninject. how can change default web api dependency resolver framework?

for example structuremap container set this:

        var container = new structuremap.container(m=>m.scan(x =>                                                              {               x.thecallingassembly();                x.withdefaultconventions();                                                               })); 

but can not set in web api life.

check out structuremap.dnx project:

https://github.com/structuremap/structuremap.dnx

usage

the package contains single, public extension method, populate. it's used populate structuremap container using set of servicedescriptors or iservicecollection.

example

using system; using microsoft.extensions.dependencyinjection; using structuremap;  public class startup {     public iserviceprovider configureservices(iservicecollection services)     {         services.addmvc();         services.addwhatever();          var container = new container();          // can populate container instance in 1 of 2 ways:          // 1. use structuremap's `configure` method , call         //    `populate` on `configurationexpression`.          container.configure(config =>         {             // register stuff in container, using structuremap apis...              config.populate(services);         });          // 2. call `populate` directly on container instance.         //    internally call `configure`.          // register stuff in container, using structuremap apis...          // here populate container using service collection.         // register services collection         // container appropriate lifetime.         container.populate(services);          // finally, make sure return iserviceprovider. makes         // dnx use structuremap container resolve services.         return container.getinstance<iserviceprovider>();     } } 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -