Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.45 KB

Readme.md

File metadata and controls

42 lines (29 loc) · 1.45 KB

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