Castle Windsor Registration
interface IUserService
class LocalUserService : IUserService
class RemoteUserService : IUserService
interface IUserRepository
class UserRepository : IUserRepository
If I have the following interfaces and classes where the classes IUserService
have a dependency on IUserRepository
. I can register these components by doing something like:
container.AddComponent("LocalUserService", typeof(IUserService), typeof(LocalUserService));
container.AddComponent("RemoteUserService", typeof(IUserService), typeof(RemoteUserService));
container.AddComponent("UserRepository", typeof(IUserRepository), typeof(UserRepository));
... and get the service I want by calling:
IUserService userService = container.Resolve<IUserService>("RemoteUserService");
However, if I have the following interfaces and classes:
interface IUserService
class UserService : IUserService
interface IUserRepository
class WebUserRepository : IUserRepository
class LocalUserRepository : IUserRepository
class DBUserRepository : IUserRepository
How do you register these components so that the component IUserService
can "choose" which repository to deploy at runtime? My idea is to let the user choose which repository to request from by providing 3 radio buttons (or whatever) and prompting the container to allow a new one every time IUserService
.
a source to share