Ejemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimsIdentity.DefaultRoleClaimType;

            string connectionString = ConfigurationManager.ConnectionStrings["ElateServiceConnection"].ConnectionString;
            CustomerServiceModule     customerServiceModule    = new CustomerServiceModule();
            ExecutorServiceModule     executorServiceModule    = new ExecutorServiceModule();
            IndentServiceModule       indentServiceModule      = new IndentServiceModule();
            UserActivityServiceModule userActivityModule       = new UserActivityServiceModule();
            UnitOfWorkModule          unitOfWorkModule         = new UnitOfWorkModule(connectionString);
            UnitOfUserActivityModule  unitOfUserActivityModule = new UnitOfUserActivityModule(connectionString);
            AutoMapperModule          mapperModule             = new AutoMapperModule();
            var kernel = new StandardKernel(customerServiceModule, executorServiceModule, indentServiceModule, userActivityModule,
                                            unitOfWorkModule, unitOfUserActivityModule, mapperModule);

            // Web Api
            // System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = new Ninject.Web.WebApi.NinjectDependencyResolver(kernel);

            // MVC
            // System.Web.Mvc.DependencyResolver.SetResolver(new Ninject.Web.Mvc.NinjectDependencyResolver(kernel));
            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["ElateServiceConnection"].ConnectionString;

            CustomerServiceModule     customerServiceModule    = new CustomerServiceModule();
            ExecutorServiceModule     executorServiceModule    = new ExecutorServiceModule();
            IndentServiceModule       indentServiceModule      = new IndentServiceModule();
            UserActivityServiceModule userActivityModule       = new UserActivityServiceModule();
            UnitOfWorkModule          unitOfWorkModule         = new UnitOfWorkModule(connectionString);
            UnitOfUserActivityModule  unitOfUserActivityModule = new UnitOfUserActivityModule(connectionString);
            AutoMapperModule          mapperModule             = new AutoMapperModule();
            var kernel = new StandardKernel(customerServiceModule, executorServiceModule, indentServiceModule, userActivityModule,
                                            unitOfWorkModule, unitOfUserActivityModule, mapperModule);

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
                RegisterServices(kernel);
                GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }