arch / UnitOfWork

A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, multiple database with distributed transaction supported, and MySQL multiple databases/tables sharding supported.
MIT License
1.34k stars 343 forks source link

Add custom method to a custom repository #140

Open josemojena opened 4 years ago

josemojena commented 4 years ago

Hi, how I can add a custom method to the custom repository, now when I get the repository using _unitOfWork.GetRepository<User>(hasCustomRepository: true) its impossible to get the custom methods available inside the UserRepository, always I have to convert it to UserRepository using something like this var userRepository = _unitOfWork.GetRepository<User>(hasCustomRepository: true) as UsersRepository;, so is there some way to get access to the custom methods without converting it manually

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.61. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

djechelon commented 3 years ago

I had to do a tricky and horrible alternative instead 🤢

I declared the custom repository as custom service and injected it

services.AddUnitOfWork<TContext>()
            .AddCustomRepository<TEntity, TEntityRepository>()
            .AddScoped(serviceProvider => (MyEntityRepository)serviceProvider.GetRequiredService<IRepository<TEntity>>());

Maybe you could create an extension method (edit: no you can't)