2010-07-12 52 views
0

我的控制器直接使用服务而不是存储库。这些服务被放置在ApplicationServices项目中:s#arp架构查询 - 服务和存储库

public XYZService 
     (
      IBlaRepository BlaRepository, 
      IBla1Repository Bla1Repository 
     ) 
     { 
      Check.Require(BlaRepository != null, "BlaRepository may not be null"); 
      this.BlaRepository = BlaRepository; 
     .... 

这工作正常。

该库是这样实现的:

public interface IBlaRepository : IRepository<Bla> (placed in Core/DataInterfaces) 

public class BlaRepository : Repository<Bla>, IBlaRepository (placed in Data) 

有时候,我可以只使用“纯”犀利架构库。有没有办法让他们进入上述服务?我需要在某处注册吗?

为了澄清这一点 - 服务的构造器看起来是这样的:

public XYZService 
     (
      Repository<UUU> UUURepository 

...

希望这是有道理的。

谢谢!

克里斯

+0

嗯,我认为这是通过ComponentRegistrar.AddComponentsTo小号#ARP,但这container.AddComponentLifeStyle自动完成( “repositoryWithTypedId” 的typeof(IRepositoryWithTypedId <,>)的typeof(RepositoryWithTypedId <,>),LifestyleType.PerWebRequest );它在最新的S#arp版本中被删除了吗? – queen3 2010-07-12 15:16:55

+0

谢谢。如果我按照所描述的那样实现接口,那么“自动”就可以工作 - 我正在用'普通的s#arp代表'来锻炼一下。 – cs0815 2010-07-12 15:30:39

回答

2

克里斯, 所有你需要做的是指您的存储库这样:

private readonly IRepository<Bla> _blaRepository; 

    public BlaService(IRepository<Bla> blaRepository) 
    { 
     _blaRepository = blaRepository; 
    } 

这将使温莎到存储库注入到你的控制器没有通过你到别的需要。

亚历克

+0

mmmh我想我试过 - 必须检查。不管怎么说,还是要谢谢你。 – cs0815 2010-07-12 15:31:50