结构图和实体框架4.1

时间:2011-08-07 17:13:03

标签: model-view-controller structuremap

我的存储库类的格式如下:

  public partial class CategoryRepository : EfRepository<Category>, ICategoryRepository
{
    public CategoryRepository(IUnitOfWork uow)
        : base(uow)
    { }
}
public partial interface ICategoryRepository : IRepository<Category>
{
}

我需要有很多相同的格式。这是一项漫长无聊的工作。 对于bootstrapper,我使用泛型扫描。

 ObjectFactory.Initialize(x =>
        {              
            x.Scan(y =>
            {
                y.AssemblyContainingType(typeof(IRepository<>));
                y.ConnectImplementationsToTypesClosing(typeof(IRepository<>)).
                    OnAddedPluginTypes(z => z.HybridHttpOrThreadLocalScoped());

            });

工作得很好,但如果我不需要像上面那样声明所有的存储库类,那就更好了。无论如何要绕过这个?我正在使用structuremap 2.6.2

感谢所有, Nam Vo。

1 个答案:

答案 0 :(得分:0)

是的,你可以使用泛型。声明一个defaultrepository或类似的东西:

    public class DefaultRepository<TEntity> : 
EfRepository<TEntity>, IRepository<TEntity>

确保将TEntity限制在适当的类型。