protected void Application_Start() { Version version = Assembly.GetExecutingAssembly().GetName().Version; Application["Version"] = String.Format("{0}.{1}", version.Major, version.Minor); Application["Name"] = ConfigurationManager.AppSettings["ApplicationName"]; //create empty container //scan this assembly for any installers to register services/components with Windsor Container = new WindsorContainer().Install(FromAssembly.This()); //API controllers use the dependency resolver and need to be initialized differently than the mvc controllers GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(Container.Kernel); //tell ASP.NET to get its controllers from Castle ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(Container.Kernel)); //initialize NHibernate ConnectionStringSettings connectionString = ConfigurationManager.ConnectionStrings[Environment.MachineName]; if (connectionString == null) throw new ConfigurationErrorsException(String.Format("Connection string {0} is empty.", Environment.MachineName)); if (String.IsNullOrWhiteSpace(connectionString.ConnectionString)) throw new ConfigurationErrorsException(String.Format("Connection string {0} is empty.", Environment.MachineName)); string mappingAssemblyName = ConfigurationManager.AppSettings["NHibernate.Mapping.Assembly"]; if (String.IsNullOrWhiteSpace(mappingAssemblyName)) throw new ConfigurationErrorsException( "NHibernate.Mapping.Assembly key not set in application config file."); var nh = new NHInit(connectionString.ConnectionString, mappingAssemblyName); nh.Initialize(); SessionFactory = nh.SessionFactory; AutoMapConfig.RegisterMaps(); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ModelBinderConfig.RegisterModelBinders(ModelBinders.Binders); AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier; }
public void CompositionRoot_ShouldBeAbleToBuildAllRootTypes() { // Arrange NinjectWebCommon.Start(); AutoMapConfig.RegisterMappings(); var writer = new HtmlTextWriter(TextWriter.Null); var req = new HttpRequest("/asd.png", "http://localhost/asd.png", ""); var res = new HttpResponse(writer); var httpContext = new HttpContext(req, res); HttpContext.Current = httpContext; var owinEnv = new Dictionary <string, object> { { $"{IdentityOwinPrefix}{typeof(IApplicationUserManager).AssemblyQualifiedName}", new Mock <IApplicationUserManager>().Object }, { $"{IdentityOwinPrefix}{typeof(IApplicationSignInManager).AssemblyQualifiedName}", new Mock <IApplicationSignInManager>().Object } }; httpContext.Items[OwinEnvironmentKey] = owinEnv; var mvcAssembly = typeof(HomeController).Assembly; var rootTypes = mvcAssembly.GetExportedTypes() .Where(type => typeof(IController).IsAssignableFrom(type) || typeof(IHub).IsAssignableFrom(type)) .Where(type => !type.IsAbstract && !type.IsGenericTypeDefinition) .Where(type => type.Name.EndsWith("Controller") || type.Name.EndsWith("Hub")); // Act & Assert foreach (var type in rootTypes) { Assert.DoesNotThrow(() => NinjectWebCommon.Kernel.Get(type)); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); services.AddControllers(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddTransient <IEmployeeRepository, EmployeeRepository>(); services.AddTransient <IEmployeeBL, EmployeeBL>(); AutoMapConfig.Initialize(); }
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup AreaRegistration.RegisterAllAreas(); StructuremapMvc.Start(); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); AutoMapConfig.ConfigureAutoMapper(); BundleConfig.RegisterBundles(BundleTable.Bundles); }
void Application_Start(object sender, EventArgs e) { BaseDbInstanceManger.RegisterType(); InstanceManger.RegisterType(); // 在应用程序启动时运行的代码 BaseDatabaseConfig.SetDbInfo(); AutoMapConfig.CreateMaps(); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AutoMapConfig.Register(); var container = new Container(); container.Register <IFarmaciaRepository, FarmaciaRepository>(); container.Register <IUsuarioRepository, UsuarioRepository>(); container.Register <IProdutoRepository, ProdutoRepository>(); container.Register <IPrecoRepository, PrecoRepository>(); container.Register <DataBaseContext>(Lifestyle.Singleton); container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.Verify(); DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); }
public void Configuration(IAppBuilder app) { // 有关如何配置应用程序的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkID=316888 // 使应用程序可以使用 Cookie 来存储已登录用户的信息 // 并使用 Cookie 来临时存储有关使用第三方登录提供程序登录的用户的信息 // 配置登录 Cookie app.UseCookieAuthentication(new CookieAuthenticationOptions { CookieName = "lyq.Cookie", AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, //Cookies LoginPath = CookieAuthenticationDefaults.LoginPath, //Account/Login LogoutPath = CookieAuthenticationDefaults.LogoutPath, //Account/Logout ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter //ReturnUrl }); LoggerConfig.RegisterLog4net("/Configs/log4net.config"); AutoMapConfig.RegisterMapper(); AutoFacMvcConfig.RegisterContainer(); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
public static void MyClassInitialize(TestContext testContext) { BaseDatabaseConfig.SetDbInfo(); AutoMapConfig.CreateMaps(); }
public static void MyClassInitialize(TestContext testContext) { BaseDbInstanceManger.RegisterType(); BaseDatabaseConfig.SetDbInfo(); AutoMapConfig.CreateMaps(); }
public void Setup() { mapper = new AutoMapConfig(); AutoMapConfig.Initialize(); }