Please help me to solve a problem. I use NancyFx and for code optimisation i decided to use only OWIN SelfHost without usage NancyFx SelfHost. I create windows service where i place code (OnStart function)
_s7Comm = _container.Resolve<IS7Comm>(); // s7 controller class connection _context = Rhs60Hub.HubContext; // hub context // events for send info to hub from s7 _s7Comm.OnErrorEvent += S7CommOnErrorEvent; ...... var startup = _container.Resolve<Startup>(); // use Unity IoC Service = WebApp.Start("http://+:8081/", startup.Configuration);
Start service with a help of Windows Service Helper - everythin is working. Do service stop, code (OnStop function)
_s7Comm.OnErrorEvent -= S7CommOnErrorEvent; .....
_s7Comm.Dispose(); // free all tasks in object
Service.Dispose(); // stop nancy
start again - branch with initialise NancyFX does not start but gives exception NullReferenceException. my Start Class for Owin
app.UseCors(CorsOptions.AllowAll); app.MapSignalR("/signalr", new HubConfiguration() { EnableDetailedErrors = true, EnableJSONP = true, EnableJavaScriptProxies = true }); app.UseNancy(options => options.Bootstrapper = new Bootstrapper(UnityHelper.GetConfiguredContainer())); <- error here
For test I determine start of NancyFX with a help of package NancyFx SelfHost - all is good, start? stop and restar.
(OnStart function)
_s7Comm = _container.Resolve(); // s7 controller class connection _context = Rhs60Hub.HubContext; // hub context
// events for send info to hub from s7 _s7Comm.OnErrorEvent += S7CommOnErrorEvent; ......
_host = new NancyHost(new Uri("http://localhost:8082"), new Bootstrapper(_container));
_host.Start();
var startup = _container.Resolve(); // use Unity IoC
Service = WebApp.Start("http://+:8081/", startup.Configuration);
and remove string from Start class with definitions for nancyFx
Where can be a problem with usage host in OWIN? Code debuf shows that container is initialised and all dependencies are present. How I can discover with dependence is not present? Show you stack tracing
> в Microsoft.Practices.Unity.UnityDefaultBehaviorExtension.SetLifetimeManager( Type lifetimeType, String name, LifetimeManager lifetimeManager)\r\n
в Microsoft.Practices.Unity.UnityDefaultBehaviorExtension.OnRegisterInstance (Object sender, RegisterInstanceEventArgs e)\r\n
в System.EventHandler1.Invoke(Object sender, TEventArgs e)\r\n
1.Initialise()\r\n
в Microsoft.Practices.Unity.UnityContainer.RegisterInstance (Type t, String name, Object instance, LifetimeManager lifetime)\r\n
в Microsoft.Practices.Unity.UnityContainerExtensions.RegisterInstance[TInterface](IUnityContainer container, TInterface instance, LifetimeManager lifetimeManager)\r\n
в Nancy.Bootstrappers.Unity.UnityNancyBootstrapper.RegisterBootstrapperTypes(IUnityContainer applicationContainer)\r\n
в Nancy.Bootstrapper.NancyBootstrapperBase
в Nancy.Owin.NancyMiddleware.UseNancy(NancyOptions options)\r\n
в Owin.AppBuilderExtensions.UseNancy(IAppBuilder builder, NancyOptions options)\r\n
в Owin.AppBuilderExtensions.UseNancy(IAppBuilder builder, Action`1 configuration)\r\n
в RHS60SystemService.Startup.Configuration(IAppBuilder app) в c:\......\Startup.cs:строка 16" string
string 16 is
app.UseNancy(options => options.Bootstrapper = new Bootstrapper(UnityHelper.GetConfiguredContainer()));