I’m trying to convert some applications that use Ninject to Castle Windsor so that I can eliminate some dependencies.
I can’t figure out how to achieve some of Ninject’s functionality using the container.Register methods in windsor.
Namely (in Ninject):
Kernel.Bind<ISessionProvider>().To<UnitOfWorkSessionProvider>();
Kernel.Bind<ISessionProvider>().To<ThreadSafeSessionProvider>()
.WhenClassHas<RequireThreadSafeSession>();
This tells Ninject that when building a class that has ISessionProvider in the constructor, use UnitOfWorkSessionProvider, unless it has the attribute RequireThreadSafeSession, in which case it is given a ThreadSafeSessionProvider.
Question one- can this be done in Windsor? The documentation is a bit confusing.
Question two- how does one do this? It seems like conditional binding is permitted in the AllTypes configuration class, but the usage patterns are not quite as transparent
You can use UsingFactoryMethod in the registration API to use late-binding and decide on the implementation. Try this: