The Setup: I have a almost out-of-the-box Nancy + TinyIoC setup running a webservice which works fine. It depends on various (AsSingleton) service classes. However these are not injected as Singletons, a new instance is created each time.
I have setup the Nancy bootstrapper as follows:
class MyBootStrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
var cp = new CertificateProvider();
container.Register(cp).AsSingleton();
}
}
Are you sure your bootstrapper is being used? It's not public so it may well just be using the built in one where the default convention is multiple instances for non-interface dependencies.
As with Daniel's answer.. you also don't need the AsSingleton if you are making an instance registration, you may as well just do:
So it's only created as needed.