开发者

Windsor Dependency Injection Problem with generics

开发者 https://www.devze.com 2023-02-14 08:35 出处:网络
I have an Interface IRepo <Entity>. I have a generic implementation Repo<Entity>. Now i just do the following

I have an Interface IRepo <Entity>. I have a generic implementation Repo<Entity>. Now i just do the following

Container.Register(AllTypes.FromAssemblyNamed("assemblyname").Pick() .WithService.DefaultInterface() .Configure(c => c.LifeStyle.PerWebRequest))

and register all the interface with respective implementations. This seems to work fine.

My Problem arises when i try to be more specific. If i try to map IRepo<Person> with Person being a class subclassing Entity with <UserRepo> using

Container.Register(C开发者_如何学Pythonomponent.For(IRepo<Person>).ImplementedBy(UserRepo).LifeStyle.PerWebRequest);

It does not seem to work.

The order in which i am doing this is that i am registering this specific implementation and then loading and registering all the interfaces to types from the assembly.

It does not seem to work.


DefaultInterface doesn't support generics. You can use AllInterfaces instead or a custom strategy via Select method

0

精彩评论

暂无评论...
验证码 换一张
取 消