Exemple #1
0
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder appBuilder)
        {
            //System.Threading.Thread.Sleep(70000);//.
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Fingrid.Messaging"].ConnectionString;

            Container = new SimpleInjector.Container();
            //Container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
            Container.Options.DefaultScopedLifestyle = new SimpleInjector.Lifestyles.AsyncScopedLifestyle();
            Container.RegisterAllDependencies(connectionString);

            Container.Verify();


            try
            {
                //GlobalConfiguration.Configuration.DependencyResolver =
                //    new SimpleInjector.Integration.WebApi.SimpleInjectorWebApiDependencyResolver(Container);
                //Fingrid.Infrastructure.Common.Logging.ILogger logger = Container.GetInstance<Fingrid.Infrastructure.Common.Logging.ILogger>();

                // Configure Web API for self-host.
                HttpConfiguration config = new HttpConfiguration()
                {
                    DependencyResolver = new SimpleInjector.Integration.WebApi.SimpleInjectorWebApiDependencyResolver(Container)
                };

                //config.EnableCors();

                //  Enable attribute based routing
                //  http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
                config.MapHttpAttributeRoutes();

                //config.Routes.MapHttpRoute(
                //    name: "DefaultApi",
                //    routeTemplate: "api/{controller}/{id}",
                //    defaults: new { id = RouteParameter.Optional }
                //);

                appBuilder.UseWebApi(config);
            }
            catch (Exception)
            {
                //logger.LogError(ex);
                throw;
            }
        }