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)
-
0
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.
-
0
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
-
0
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.
-
0
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.
-
0
Thanks Hilal. So what you do basically is register an instance of Repository per DbSet in each DbContext?
-
0
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).
-
0
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