Skip to content

TheDanielDoyle/ServiceProfiles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Service Profiles

A framework for splitting out the registration of services in IServiceCollection into profiles. No more large Startup.cs classes.

Quick start (The easy way)

  1. When building an IHost, add ConfigureServicesWithProfiles() method to the IHostBuilder to load Service Profiles in the executing assembly.
IHostBuilder builder = Host.CreateDefaultBuilder(args).ConfigureServicesWithProfiles();

Quick start (The manual way)

  1. Instantiate a HostServiceProfileLoader() class.

  2. Execute one of the Load() methods and pass in the IServiceCollection, IConfiguration and IHostEnvironment.

IHostServiceProfileLoader loader = new HostServiceProfileLoader();
loader.Load(services, Configuration, Environment);
loader.LoadFromAssembly(services, Configuration, Environment, typeof(Program).Assembly);
loader.LoadFromAssemblies(services, Configuration, Environment, new Assembly[] {typeof(Program).Assembly});

Create Service Profiles

  1. Create profile classes that derive from HostServiceProfile and implement the Configure() method.
public class TestProfile : HostServiceProfile
{
    public override void Configure(IHostServiceProfileContext context)
    {
        context.Services.AddBeer();
    }
}

Samples

See the following sample https://github.com/TheDanielDoyle/ServiceProfiles/blob/develop/Samples/ServiceProfiles.Samples.Console/Program.cs

About

A framework for splitting out the registration of services in IServiceCollection into profiles. No more large Startup.cs classes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages