Skip to content

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

Closed
@bart-degreed

Description

@bart-degreed

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions