Enabling Silverback
Enabling the bus
Silverback's main component is the internal in-memory message bus and pretty much all other features are built on top of that.
The first mandatory step to start using Silverback is to register the core services (internal bus) with the .net core dependency injection.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSilverback();
}
}
Configuring Silverback
The AddSilverback method highlighted in the previous chapter returns an ISilverbackBuilder that exposes all the methods needed to configure Silverback and wire everything up.
The several configuration options will are exhaustively presented in each dedicated section of this documentation but here is a basic sample startup.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services
.AddSilverback()
.WithConnectionToMessageBroker(options => options
.AddKafka())
.AddEndpointsConfigurator<OrdersEndpointsConfigurator>()
.AddEndpointsConfigurator<ProductsEndpointsConfigurator>()
.AddScopedSubscriber<OrderEventsSubscriber>()
.AddScopedSubscriber<ProductEventsSubscriber>();
}
}
Note that AddSilverback should be called only once but you can use the ConfigureSilverback extension method on the IServiceCollection to retrieve the ISilverbackBuilder instance once again.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services
.AddSilverback()
.WithConnectionToMessageBroker(options => options
.AddKafka());
services
.AddOrdersFeature()
.AddProductsFeature();
}
}