Skip to content
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

services.AddShovel to accept transform method injection #61

Closed
althunibat opened this issue Dec 12, 2021 · 3 comments · Fixed by #63
Closed

services.AddShovel to accept transform method injection #61

althunibat opened this issue Dec 12, 2021 · 3 comments · Fixed by #63
Labels
enhancement New feature or request

Comments

@althunibat
Copy link

passing transform method lacks dependency injection, shovel class may have dependencies to be injected to enrich the transformed events.

@alexeyzimarev
Copy link
Contributor

Good point. The issue, as always, is to be able to distinguish between those services, as each shovel (will be called a Gateway in the next version) might need a different one. If you look at the current subscription builder and all the stuff related to registrations of subscriptions, you'll see how cumbersome it becomes...

Still, if we agree that the first working solution would be ok assuming only one shovel needs to be there in one application, I can enable registering a shovel without providing a function.

So, instead of:

services.AddShovel<AllStreamSubscription, AllStreamSubscriptionOptions, EventStoreProducer>("myShovel", x => {...});

You could do this:

services.AddSingleton<MyTransformer>();
services.AddSingleton<RouteAndTransform>(sp => sp.GetRequiredService<MyTransformer>.Transform);
services.AddShovel<AllStreamSubscription, AllStreamSubscriptionOptions, EventStoreProducer>("myShovel");

That can be done quickly.

@alexeyzimarev alexeyzimarev added the enhancement New feature or request label Dec 12, 2021
@althunibat
Copy link
Author

we can decide on shovel transform instance upon declaring it, this way it is not one instance which implements RouteAndTransform

services.AddSingleton<MyTransformer>();
services
    .AddShovel<AllStreamSubscription, AllStreamSubscriptionOptions, EventStoreProducer>(
        "IntegrationSubscription",
        sp=>sp.GetRequiredService<MyTransformer>.Transform
    );

@alexeyzimarev
Copy link
Contributor

True, so, basically, for the registration a simple improvement would to accept a function to resolve the transformer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants