Skip to main content.

Site Map

Site Map

Startup Extensions

.NET Core normally starts a service by calling void ConfigureServices(IServiceCollection services) and then void Configure(IApplicationBuilder app). The SERVICE BRICK platform utilizes a (3) three phase startup sequence.

  • AddBrick() Extension Method - This method is called during the void ConfigureServices(IServiceCollection services) method
  • RegisterBrick() Extension Method - This method is first called for all hosted Service Bricks during the void Configure(IApplicationBuilder app) method
  • StartBrick() Extension Method - This method is called last for all hosted Service Bricks during the void Configure(IApplicationBuilder app) method. This should also invoke any seeding or migration code to bring your service up to date for a new release.

Our platform splits the void Configure(IApplicationBuilder app) method into a pre and post method. This extra step allows all Service Bricks to register their business rules into the pipeline. This allows extensibility so that all logic changes are fully configured before starting each Service Brick. It additionally provides a way for you to customize and change any pre-built services, add, remove or change any functionality to your needs.

Naming Conventions

To ensure that extension methods are not overlapped, we have defined the following strategy:
[Add/Register/Start]Brick[Module Name][LayerName]
For example, the Logging API Controller Service Brick, would have (3) three extension methods defined:

  • AddBrickLoggingApiController, RegisterBrickLoggingApiController, StartBrickLoggingApiController

Ordering

The first method call for each phase must all be for the Core library. This sets up any platform dependency injection requirements. These are defined as:

  • AddBrickCore
  • RegisterBrickCore
  • StartBrickCore

Ordering for the layers of a module only has one requirement, which is the Common project is called last during Startup. The Common project may contain Seeding to create tables, create required data or more during the StartBrick extension method. It is important for the storage providers to be registred and started first, so that they are available.

Additionally, you should call each Service Brick in order of dependencies. If a Service Brick has a dependency on Service Brick XYZ, then you should call Service Brick XYZ first. If there are no dependencies, then order is irrelevent.

For example, to startup the Logging Service Brick, you would call the following extensions methods in the following order.

  • AddBrickLoggingApi, RegisterBrickLoggingApi, StartBrickLoggingApi
  • AddBrickLoggingApiController, RegisterBrickLoggingApiController, StartBrickLoggingApiController
  • AddBrickLogging[StorageProvider], RegisterBrickLogging[StorageProvider], StartBrickLogging[StorageProvider]
  • AddBrickLogging, RegisterBrickLogging, StartBrickLogging - Always call the Common project last

Startup Class

We provide a simple startup class that makes setting up your microservice a little easier. This file is used to enfore the (3) three phase startup of all Service Bricks.


public class Startup : ServiceBrick.Startup
    {
        public Startup(IConfiguration configuration) : base(configuration) { }

        public virtual void ConfigureServices(IServiceCollection services)
        {
            base.CustomConfigureServices(services);
        }

        public virtual void Configure(IApplicationBuilder app)
        {
            base.CustomConfigure(app);

            var logger = app.ApplicationServices.GetRequiredService<ILogger<Startup>>();
            logger.LogInformation("Application Is Now Started");
        }

        public override void AddBricks(IServiceCollection services)
        {
            base.AddBricks(services);

            // Call All Service Bricks Here
        }

        public override void RegisterBricks(IApplicationBuilder app)
        {
            base.RegisterBricks(app);

            // Call All Service Bricks Here
        }

        public override void StartBricks(IApplicationBuilder app)
        {
            base.StartBricks(app);

            // Call All Service Bricks Here
        }
    }