开发者

Setting repositories and providers

开发者 https://www.devze.com 2023-04-12 00:04 出处:网络
Im having a little bit of a problem trying to figure out how to do the following. My apologies if thhe following seems idiotic, just new to Castle.Windsor.

Im having a little bit of a problem trying to figure out how to do the following. My apologies if thhe following seems idiotic, just new to Castle.Windsor.

Right, In my application repositories should point to diferent dbs. They all share a abstract class (Db methods abstraction) but there is no correlation between them. So I have something like this:

public class UserService : IUserService
{
   private readonly IUserRepository _repository;
   public UserService(IUserRepository repository) { _repository = repository; }
   ...
}

public class UserRepository : Mongo, IUserRepository
{
  public UserRepository(DatabaseHosts.Users UsersHost) : base(UsersHost) { }
  ...
}

All configuration settings are strongly typed and so far I am calling a Installer for the Set开发者_如何学JAVAtings Service before i call Install on the rest.

My question would be: Do i have to register services and Respositories or there is something im missing?

I think, We could allow access to the DbHost property from the Service, but i rather like not. We also have providers to external systems which might need some sort of initialization.

So far i have soemthing like this:

public class ServicesInstaller : IWindsorInstaller
{
   public void Install(IWindsorContainer container, IConfigurationStore store)
   {
       container.Register(Component.For<IUserService>()
                .ImplementedBy<IUserService>()
                .LifeStyle.Singleton);
   }
}

Ta


   public void Install(IWindsorContainer container, IConfigurationStore store)
   {
       container.Register(Component.For<IUserService>()
                .ImplementedBy<UserService>()
                .LifeStyle.Singleton);
   }

you have to register the concrete service "UserService" to the interface in order to allow the container to determine which concrete to resolve.

0

精彩评论

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

关注公众号