Our program
With our main.cs
file filled out, here's how it will look. As this is a microservice that may run multiple instances for performance reasons when training the network, I have added leadership capabilities via Topshelf.Leader
. I have highlighted the relevant sections of code that pertain to this:
static void Main(string[] args) { var builder = new ContainerBuilder(); // Service itself builder.RegisterType<MLMicroService>() .AsImplementedInterfaces() .AsSelf() ?.InstancePerLifetimeScope(); builder.RegisterType<Logger>().SingleInstance(); var container = builder.Build(); XmlConfigurator.ConfigureAndWatch(new FileInfo(@".log4net.config")); HostFactory.Run(c => { c?.UseAutofacContainer(container); c?.UseLog4Net(); c?.ApplyCommandLineWithDebuggerSupport(); c?.EnablePauseAndContinue(); c?.EnableShutdown(); c?.OnException(ex => { Console.WriteLine(ex.Message); }); c?.UseWindowsHostEnvironmentWithDebugSupport(); c?.Service<MLMicroService>(s => { s.ConstructUsingAutofacContainer...