I am using Nancy with TinyIoC to solve dependencies.
One of the dependencies, in particular, should be single for the application-life cycle.
If I do this with a standard constructor, it works:
container.Register<IFoo, Foo>().AsSingleton();
but if I try this with some arguments on the constructor, it is not:
container.Register<IFoo>((c, e) => new Foo("value", c.Resolve<ILogger>())).AsSingleton();
// FAILS with error "Cannot convert current registration of Nancy.TinyIoc.TinyIoCContainer+DelegateFactory to singleton"
Without .AsSingleton(), it works again, but I don't get singleton:
container.Register<IFoo>((c, e) => new Foo("value", c.Resolve<ILogger>()));
// Works, but Foo is not singleton
Any ideas? I think the error should be obvious, but I cannot find it. I used all my google-foo.
EDIT
The code works here:
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container);
}
}
source
share