LazyStack

ProjectOptions Directive

ServiceRegistrations

For Lambda projects and WepApi projects, you often want to register classes for Dependency Injection. LazyStack generates Startup class method ConfigureSvcs() and inserts service registration statements into it. Consider the following service registrations from the PetStore example:

  LambdaProjects:
    ServiceRegistrations:
    - services.AddSingleton<PetStoreRepo.IPetStoreRepo,PetStoreRepo.PetStoreRepo>:(); 

  WebApiProjects:
    ServiceRegistrations:
    - services.AddSingleton<PetStoreRepo.IPetStoreRepo,PetStoreRepo.PetStoreRepo>();

The LazyStack generated ConfigureSvcs method in the lambda projects would look like this:

public partial class Startup
{
    public void ConfigureSvcs(IServiceCollection services)
    {
        services.AddSingleton<PetStoreRepo.IPetStoreRepo,PetStoreRepo.PetStoreRepo>();
    }
}

In this particular example we are adding a singleton but you can use any valid service registration statement. Note that we do not need to add Controller classes with an explicit service call because the Startup routine also includes the usual services.AddControllers() call.

Project types supporting service registrations include:

  • LambdaProjects
  • WebApiProjects

Note: LazyStack only generates a single WepApiProject.