Hi everyone, and thanks in advance for any assistance.
In following with practice seen around quite a few examples that use Autofac injection, I've noticed the above mentioned behaviour. Implementing IStartable means Start() will be fired upon the container being built. Cool.
Then when I create the host as follows
var host = HostFactory.New(x =>
{
x.Service<IStartable>(s =>
{
s.ConstructUsing(name => container.Resolve<IStartable>());
s.WhenStarted(tc => tc.Start());
s.WhenStopped(_ =>
{
Console.WriteLine("Service is stopping");
container.Dispose();
});
});
x.RunAsLocalSystem();
});
Start() gets hit again - no problem, I understand why here too.
Having said that, is it just numerous examples out in the wild that are ignoring this fact, and let it run twice, when in fact they should either
a) not be calling Start() in the WhenStarted callback when implementing Autofac.IStartable; or
b) not be implementing Autofac.IStartable, and instead create their own interface for resolution in ConstructUsing, and hit anything you want at startup via the Topshelf WhenStartedCallback
Again, thanks for any push in a preferable direction.