示例#1
0
        /// <summary>
        /// Configurations the specified application builder.
        /// </summary>
        /// <param name="appBuilder">The application builder.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public void Configuration(IAppBuilder appBuilder)
        {
            if (appBuilder == null)
            {
                throw new ArgumentNullException(nameof(appBuilder));
            }

            appBuilder.UseCors(CorsOptions.AllowAll);
            appBuilder.UseNinjectMiddleware(() => Ninject.ConfiguredKernel);
            appBuilder.UseNinjectWebApi(WebApi.GetConfig(OData.CreateModel()));

            appBuilder.Use <NotFoundMiddleware>();
        }
示例#2
0
        public void Configuration(IAppBuilder appBuilder)
        {
            try
            {
                if (appBuilder == null)
                {
                    throw new ArgumentNullException(nameof(appBuilder));
                }

                //// a) Load all the modules (bindings of all public ninjectmodules defined inside the dll's that matches the pattern "Ninject.Extensions.*.dll", "Ninject.Web*.dll")
                ////    into the kernel
                var kernel = NinjectConfig.CreateKernel();

                //// appBuilder.UseNLog();
                appBuilder.UseNinjectMiddleware(() => kernel);
                appBuilder.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

                appBuilder.UseNinjectWebApi(WebApi.GetConfig());

                var context = new OwinContext(appBuilder.Properties);
                var token   = context.Get <CancellationToken>("host.OnAppDisposing");
                if (token != CancellationToken.None)
                {
                    token.Register(() =>
                    {
                        var loggingService = kernel.Get <NLog.ILogger>();

                        loggingService.Info("trying to dispose kernel");

                        if (!kernel.IsDisposed)
                        {
                            kernel.Dispose();
                            loggingService.Info("kernel disposed");
                        }
                        else
                        {
                            loggingService.Info("kernel already disposed");
                        }

                        loggingService.Info("application stopped");
                    });
                }
            }
            catch (Exception ex)
            {
                var loggingService = NLog.LogManager.GetLogger("defaultApplication");
                loggingService.Error(ex.Message);

                throw ex;
            }
        }