c# - Injecting class dynamically based on request using Unity -


i using developing mvc4 application using unity. architecture this.

public interface irepositoy<t> { }  public class datarepository<t>:irepository { } 

basically here t model.

then again

 public interface imodel  {  //property , methods  }  public class mobile: imodel 

all model classes inherit interface.

now in unity using following syntax

registertype<irepository<mobile>, datarepository<mobile>>();  

and here problem.

i want "mobile" class dependent on request url. mobile page request "mobile" class injected, if "camera" page requested camera object injected.

i using if-else. looking more sophisticated way make code more maintainable , robust. new unity , di don't know best way.

can please help?

i think you're looking @ wrong way.

all need product controller in case. base class entity product , you'd inherit class in model stuff like mobile, desktop or not. check ef inheritance:

http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/implementing-inheritance-with-the-entity-framework-in-an-asp-net-mvc-application


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -