ASP.NET MVC - Dependency Injection -


i going on dependency injection. have asp.net mvc project model named customers:

public class customers {     public id get; set;      private customer customer      public customers()     {        customer = new customer();      } } 

now suppose add classes in order eliminate dependency in above class. example, customer dependency of customers class. customers should depend on abstraction. created interface (or abstract class) named istoragecustomer

public interface istoragecustomer  { } 

now changed customers class following below:

public class customers {     public id get; set;      private istoragecustomer customer;      public customers(istoragecustomer customer)     {        this.customer = customer;      } } 

i need know if dependency has been eliminated in above class. else need do? please help. appreciated. thank you.

you can install ninject mvc. (be aware there different version each version of mvc)

this nuget manages dependency injection you.

to make ninject inject right class, should set in ninjectwebcommon file.

private static void registerservices(ikernel kernel) {     //all bindings configured here     kerenl.bind<istoragecustomer>().to<costumer>(); //if want customer instances injected everywhere expect istoragecustomer } 

also leave default constructor class want inject instances into.


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -