Configure dependency injection for Windows Service using Autofac — Part 3
This blog post is part of the series How to: Create Windows Service that schedules jobs, logs and is configurable by means of dependency injection.
In previous blog post, we’ve created a Windows Service using Topshelf and configured logging using log4net library.
When we were configuring the service host, we provided to ServiceConfigurator
a factory method that creates our service.
serviceConfigurator.ConstructUsing(() => new MyService());
If we were to use an IoC container such as Autofac, we could pass a factory method that uses that container to resolve our service.
There is also a NuGet package Topshelf.Autofac to help us with setting up dependency injection. On github page https://github.com/alexandrnikitin/Topshelf.Autofac you can find example usage.
In next and final post of this series, we will schedule jobs from our Windows Service using Quartz.