Skip to content

Assembly scanning does not work with custom open generic registrations #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bart-degreed opened this issue Apr 28, 2021 · 0 comments · Fixed by #982
Closed

Assembly scanning does not work with custom open generic registrations #981

bart-degreed opened this issue Apr 28, 2021 · 0 comments · Fixed by #982
Labels

Comments

@bart-degreed
Copy link
Contributor

When calling .AddJsonApi() combined with assembly scanning, it discards and overwrites any prior open-generic registrations.

Example:

// Startup.ConfigureServices
services.AddScoped(typeof(IResourceRepository<,>), typeof(CustomJsonApiRepository<,>));
services.AddScoped(typeof(IResourceReadRepository<,>), typeof(CustomJsonApiRepository<,>));
services.AddScoped(typeof(IResourceWriteRepository<,>), typeof(CustomJsonApiRepository<,>));

services.AddJsonApi<AppDbContext>(discovery: facade => facade.AddCurrentAssembly());

// ArticleRepository.cs
public class ArticleRepository : CustomJsonApiRepository<Article, Guid> { ... }

will add the next registration:

services.AddScoped<IResourceReadRepository<Article, Guid>, EntityFrameworkCoreRepository<Article, Guid>>();

instead of the expected:

services.AddScoped<IResourceReadRepository<Article, Guid>, CustomJsonApiRepository<Article, Guid>>();

Because of this, it is impossible to combine assembly scanning with replaced open-generic registrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 participant