0
    /// <summary>
    /// Starts up the Application.
    /// </summary>
    /// <param name="container">The container.</param>
    /// <param name="pipelines">The pipelines.</param>
    protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
    {
        base.ApplicationStartup(container, pipelines);

        container.Register<UserProvider>().AsPerRequestSingleton();
    }

The above is my existing application startup containing my TinyIoc configuration. Is there any way to take all interface registrations and turn them all into PerRequestSingletons? I can't do them 'one by one' as I have too many repositories, and I can't leave them as singletons, because it doesn't work with the way that NHibernate is set up.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
Mark Withers
  • 1,462
  • 5
  • 16
  • 34

1 Answers1

1

If you want everything to be request scoped, then try moving the registration into the ConfigureRequestContainer method rather than ApplicationStartup.

Generally this is how you handle request scoped singletons in Nancy.

Failing that you might need to look at another DI package, eg. http://nuget.org/packages/Nancy.Bootstrappers.Autofac
It has more features and conventions to deal with mass registrations.

Just nuget it, then make your bootstrapper a subclass of the bootstrapper inside the package.

Chris Sainty
  • 9,086
  • 1
  • 26
  • 31
  • ConfigureRequestContainer didn't work for me, as it killed the performance (2.8 seconds to register all our classes) – Mark Withers May 16 '12 at 13:51
  • I've given you the correct answer as I have moved to a different bootstrapper. We went with Windsor, as we've used it before – Mark Withers May 16 '12 at 13:52