In my MVC application, I'm registering all of my controllers using reflection in the Application_Start handler. This basically creates all types that are used on any controller parameter and adds it to the container.
开发者_运维百科I now have a situation where I have multiple parameters on my controller that are of the same type. Here is a simple example of my problem:
public class ClassA : ICustomType
{ ... }
public class ClassB : ICustomType
{ ... }
public class CustomController : Controller
{
public CustomController(ICustomType a, ICustomType b)
{ ... }
}
I know that I can define CustomController in my web.config file using the <components>
group. However, I'm curious to know if there is a way that I could specify 'ClassA' as my first parameter and 'ClassB' as my second parameter outside of my web.config file??
container.Register(
Component.For<ICustomType>().Named("a").ImplementedBy<ClassA>(),
Component.For<ICustomType>().Named("b").ImplementedBy<Classb>()
);
精彩评论