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

Named Service Registration - A more modular way to register named services #24

Closed
dazinator opened this issue Jun 8, 2021 · 0 comments

Comments

@dazinator
Copy link
Owner

dazinator commented Jun 8, 2021

At the moment, to register named services, you have to configure them within a callback.

 services.AddNamed<IJob>(names => {      
        names.AddSingleton<FooJob>("Foo");
        names.AddSingleton<BarJob>("Bar");
});

However in a modular system you might want different modules to be able to contribute named jobs to the system, just by adding them to the IServiceCollection. We don't want to have to couple those modules to this callback method, rather they just register services using IServiceCollection like everything else.

Consider a pattern like this:

// Module A
   services.AddNamedSingleton<IJob, FooJob>("Foo");

// Module B
  services.AddNamedSingleton<IJob, BarJob>("Bar");


// Then later before container is built
services.AddNamed<IJob>(names => {      
       // here, names will already contain the above two registrations that happened earlier so no need to add them again.
       // names.AddSingleton<FooJob>("Foo");
       // names.AddSingleton<BarJob>("Bar");
});
dazinator added a commit that referenced this issue Jun 8, 2021
dazinator added a commit that referenced this issue Jun 8, 2021
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

No branches or pull requests

1 participant