The following is the code from our main.cs method. As you can see, it follows the paradigm of all the other chapters. By now, this code should have become somewhat, if not totally, familiar to you.
The code does the following:
- Builds our Autofac container
- Registers our types and interfaces
- Configures all of our Topshelf parameters
- Provides all events
- Tells our microservice how to handle failures
- Runs our main email microservice
Here is our main.cs function block:
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.RegisterType<Logger>()?.SingleInstance();
builder.RegisterType<EmailMS>()
.AsImplementedInterfaces()
.AsSelf()
?.InstancePerLifetimeScope();
var container = builder.Build();
XmlConfigurator.ConfigureAndWatch(new FileInfo(@".log4net.config"));
HostFactory.Run(c =>
{
c?.UseAutofacContainer(container);
c?.UseLog4Net...