UnitOfWork icon indicating copy to clipboard operation
UnitOfWork copied to clipboard

Add custom method to a custom repository

Open josemojena opened this issue 5 years ago • 2 comments

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

josemojena avatar Jun 20 '20 14:06 josemojena

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.

issue-label-bot[bot] avatar Jun 20 '20 14:06 issue-label-bot[bot]

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)

djechelon avatar Jan 07 '21 13:01 djechelon