Skip to content

Decorate generic types #141

Closed
Closed

Description

@rakhimzhanov

Hi team,

Is there any way to register below generic types?

services.AddTransient(typeof(IReadRepository<,>), typeof(ReadRepository<,>));
services.Decorate(typeof(IReadRepository<,>), typeof(CachedReadRepository<,>));

Currently I got the exception like this:

Scrutor.MissingTypeRegistrationException: Could not find any registered services for type 'WebApi.Infrastructure.Repositories.IReadRepository<TEntity, TResponse>'

Activity

  1. khellang commented on Feb 28, 2021

    @khellang
    Owner

    Yeah, decorating open generic types isn't supported very well for the reasons outlined here.

    It's partly supported by having fully closed registrations in the collection (i.e. by scanning using IsAssignableTo and AsImplementedInterfaces) before decorating. In that case it will use the type arguments of the closed services to "fill in" the arguments of the decorators services.

    That's unfortunately as far as we'll get with the built-in container 😞

  2. rakhimzhanov commented on Mar 1, 2021

    @rakhimzhanov
    Author

    Dear khellang,

    Thanks for the answer and your wonderful library.
    Hope we will have this feature in the future.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions