Self-registration of external components
Self-registration of external components is new from version 7.3
When building extensions to Litium there can be different conditions that has to be fulfilled for the extension to be registered.
E.g. if we see the Microsoft Service Bus package, the service bus for Microsoft Azure is only configured if we have a connection string configured in the application configuration.
To make an extension aware of when the application is initializing, it is important to implement the Litium.Runtime.IApplicationConfiguration. For each class that implement the IApplicationConfiguration the IApplicationConfiguration.Configure method is invoked where you can register your own extensions.
Example
As you can see in the example below the Configure-method has an if-statement to decide if the services should be registered depending if the connection string is registered in the configuration.
using Litium.Runtime;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Litium.Setup.MicrosoftServiceBus
{
internal class MicrosoftServiceBusBootstrapper : IApplicationConfiguration
{
public void Configure(ApplicationConfigurationBuilder app)
{
var microsoftServiceBusConnectionString = app.Configuration.GetValue<string>("Litium:MicrosoftServiceBus:ConnectionString");
if (microsoftServiceBusConnectionString?.ContainsMicrosoftServiceBusConnectionString() ?? false)
{
app.ConfigureServices(services =>
{
services.AddSingleton<ServiceBusFactory, MicrosoftServiceBusFactory>();
});
}
}
}
}