Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Open Generics implementation in Abp #3145


User avatar
0
bilalhaidar created

Hi, I am looking at EntityFrameworkGenericRepositoryRegistrar.cs. In Castle Windsor, you can register generic interfaces with the Open Generics concepts.

Why did you need to do all the work in EntityFrameworkGenericRepositoryRegistrar.cs class to register the generic repositories and didn' just use Castle Windsor features?

Thanks


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think it is not possible to use Castle Windsor for registering generic repositories. That is why we register them one by one in EntityFrameworkGenericRepositoryRegistrar.

  • User Avatar
    0
    bilalhaidar created

    I read in their documentation you van do this;

    container.Register(Component
                 .For(typeof(IAdapterFactory<,>))
                 .ImplementedBy(typeof(AdapterFactory<,>))
                 .LifestylePerWebRequest());
    

    Doesn't this solve the problem?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think it does not because we need to register both IRepository<Entity,int> and IRepository<Entity> but I couldn't be %100 sure :). I will let halil answer this.

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    EfRepositoryBase has 3 generic arguments: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.EntityFramework/EntityFramework/Repositories/EfRepositoryBaseOfTEntityAndTPrimaryKey.cs#L19">https://github.com/aspnetboilerplate/as ... Key.cs#L19</a>

    One of them is TDbContext, the DbContext related to the Entity.

    If your application has more than one dbcontext, some entities may use one dbcontext, others may use another.

    So, we can not write this:

    For(typeof(IRepository<,>)) .ImplementedBy(typeof(EfRepositoryBase<SomeDbContext,,>))

    Notice that, also Repository's generic argument count is 2 but EfRepositoryBase's is 3.

  • User Avatar
    0
    bilalhaidar created

    Thanks Hilal. So what you do basically is register an instance of Repository per DbSet in each DbContext?

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    My name is Halil, not Hilal :D

    Not instance, but type. For each dbset in dbcontext, registering proper repository type. Instance is created when you request a type (I'm talking about class - instance relation).

  • User Avatar
    0
    bilalhaidar created

    I always thought your name is Hilal :)

    So Halil, in other words, for each DbContext, you would get the DbSet and register something like: IRepository<Person> to map to EfRepositoryBase<Person>, something like that?

    Thanks