Skip to content

Added open generic support to decoration - #25

Merged
khellang merged 1 commit into
khellang:masterfrom
nicholasham:master
Apr 28, 2017
Merged

khellang merged 1 commit into
khellang:masterfrom
nicholasham:master

Conversation

@nicholasham

@nicholasham nicholasham commented Apr 28, 2017 •

Copy link
Copy Markdown
Contributor

Hi Kristian,

I have added support for Open Generic Decorators that should close off issue #14 .

I have taken an approach where I look for existing closed types in the ServiceCollection based on the open generic service type and then use the existing closed type parameters to create a closed generic type which can be registered like a normal decorator.

The usage is like this:

services.AddSingleton<QueryHandler<MyQuery, MyResult>, MyQueryHandler>();
services.Decorate(typeof(QueryHandler<,>), typeof(LoggingQueryHandler<,>));
services.Decorate(typeof(QueryHandler<,>), typeof(TelemetryQueryHandler<,>));

I have added some unit tests to prove it works. It would be great if this could be added to your library.

Cheers
Nick

@khellang khellang added this to the v2.0.0 milestone Apr 28, 2017
@khellang
khellang merged commit 35b854f into khellang:master Apr 28, 2017
@khellang

khellang commented Apr 28, 2017 •

Copy link
Copy Markdown
Owner

Nice! I hadn't even thought about using the already registered services to "synthesize" additional registrations. Thank you so much for this! ❤️

@khellang

Copy link
Copy Markdown
Owner

I've pushed this to NuGet as part of the 2.0.0-rc version 😄

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants