public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); webBuilder.UseKestrel((context, serverOptions) => { serverOptions.ConfigureEndpointDefaults(options => options.Protocols = HttpProtocols.Http1); }); }).UseServiceProviderFactory(new WindsorServiceProviderFactory()) .ConfigureContainer <WindsorContainer>( (hostBuilderContext, container) => { container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel)); container.AddFacility <TypedFactoryFacility>(); var skipTypes = new Type[] { typeof(DataContext) }; container.Register( Classes .FromAssemblyInThisApplication(typeof(Program).Assembly) .Pick() .Unless(x => skipTypes.Any(type => type.IsAssignableFrom(x)) || x.GetInterfaces().Any() == false) .WithServiceAllInterfaces() .LifestyleSingleton() ); // Execute all installers in every library in the application container.Install(FromAssembly.InThisApplication(typeof(Program).Assembly)); } );
public static IWindsorContainer InitializeContainer(ConfigurationInstaller config) { // Windsor configuration var container = IocHelper.Container; if (_initialised) { return(container); } container.Register( Component.For <IWindsorContainer>().Instance(container) ); container.Install( config, FromAssembly.InThisApplication() ); var controllerFactory = new WindsorControllerFactory(container.Kernel); ControllerBuilder.Current.SetControllerFactory(controllerFactory); GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new WindsorHttpControllerActivator(container)); _initialised = true; return(container); }
private async void Application_Startup(object sender, StartupEventArgs e) { _container = new WindsorContainer(); // Disable property injection var propInjector = _container.Kernel.ComponentModelBuilder .Contributors .OfType <PropertiesDependenciesModelInspector>() .Single(); _container.Kernel.ComponentModelBuilder.RemoveContributor(propInjector); _container.AddFacility <TypedFactoryFacility>(); _container.Install(FromAssembly.InThisApplication()); _container.Install(FromAssembly.Named("Filtration.Parser")); // Not directly referenced so manually call its installers mapper = new MapperConfiguration(cfg => { cfg.ConstructServicesUsing(_container.Resolve); cfg.CreateMap <Theme, IThemeEditorViewModel>().ConstructUsingServiceLocator(); cfg.CreateMap <ThemeComponent, ThemeComponentViewModel>().ReverseMap(); cfg.CreateMap <ColorThemeComponent, ColorThemeComponentViewModel>().ReverseMap(); cfg.CreateMap <IntegerThemeComponent, IntegerThemeComponentViewModel>().ReverseMap(); cfg.CreateMap <StrIntThemeComponent, StrIntThemeComponentViewModel>().ReverseMap(); cfg.CreateMap <StringThemeComponent, StringThemeComponentViewModel>().ReverseMap(); cfg.CreateMap <IconThemeComponent, IconThemeComponentViewModel>().ReverseMap(); cfg.CreateMap <EffectColorThemeComponent, EffectColorThemeComponentViewModel>().ReverseMap(); cfg.CreateMap <ThemeEditorViewModel, Theme>(); }); mapper.AssertConfigurationIsValid(); var bootstrapper = _container.Resolve <IBootstrapper>(); await bootstrapper.GoAsync(); }
private void InstallComponents() { Install(FromAssembly.InThisApplication()); Install(Configuration.FromXml(GetConfigResource())); Register(Component.For <PermissionRepository>().ImplementedBy <MockPermissionRepository>().IsDefault()); }
public static IWindsorContainer CreateContainer() { var container = new WindsorContainer(); container.AddFacility <StartableFacility>(); container.Install(FromAssembly.InThisApplication()); container.Register( AllTypes.FromThisAssembly() .BasedOn <ApiController>() .LifestyleTransient()); container.Register( AllTypes.FromThisAssembly() .BasedOn <IHub>() .LifestyleSingleton()); container.Register( Component.For <ITraceWriter>() .ImplementedBy <TraceWriter>() .LifestyleSingleton()); container.Register( AllTypes.FromThisAssembly() .Pick().If(Component.IsCastleComponent)); return(container); }
private static IWindsorContainer GetContainer() { var currentFolder = AppDomain.CurrentDomain.BaseDirectory; var container = new WindsorContainer(); var installers = new List <IWindsorInstaller>(); container.Kernel.ComponentModelBuilder.AddContributor(new RequireRepositoryProperties()); var windsorConfigFile = Path.Combine(currentFolder, "windsor.xml"); if (File.Exists(windsorConfigFile)) { installers.Add(Configuration.FromXmlFile(windsorConfigFile)); } installers.AddRange(new[] { FromAssembly.InThisApplication(), FromAssembly.InDirectory(new AssemblyFilter(currentFolder, "QuadAuto.Server.*.dll")) }); container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel, true)); container.Register(Component.For <ILazyComponentLoader>().ImplementedBy <LazyOfTComponentLoader>()); container.Register(Component.For <IServerStart>().ImplementedBy <ServerStart>()); container.Install(installers.ToArray()); return(container); }
public ViewModelLocator() { this.container = new WindsorContainer(); this.container.AddFacility <TypedFactoryFacility>(); this.container.Kernel.Resolver.AddSubResolver(new CollectionResolver(this.container.Kernel, true)); this.container.Install(FromAssembly.InThisApplication()); }
private void InstallComponents() { Install(FromAssembly.InThisApplication()); Install(Configuration.FromAppConfig()); //Install(Configuration.FromXml(GetConfigResource())); var services = new ServiceCollection(); new NHibernateInstaller().Install(services); new CoreContainerRegistration().Install(services); new DataEntitiesContainerRegistration().Install(services); services.AddSingleton <IOptions <PathConfiguration>, PathConfigImplementation>(); // TODO after switch to ASP.NET Core use framework options handler services.RegisterFulltextServiceClientComponents(new FulltextServiceClientConfiguration { Url = new Uri(ConfigurationManager.AppSettings["FulltextServiceEndpoint"]), CreateCustomHandler = false }); this.AddServicesCollection(services); // Re-register UnitOfWorkProvider to satisfy dependency Register(Component.For <UnitOfWorkProvider>() .IsDefault() .UsingFactoryMethod(c => new UnitOfWorkProvider(c.ResolveAll <IUnitOfWork>().Select(x => new KeyValuePair <object, IUnitOfWork>(null, x)).ToList())) .LifestylePerWebRequest() ); }
private static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); }) .ConfigureAppConfiguration( (hostingContext, config) => { var environmentName = hostingContext.HostingEnvironment.EnvironmentName; config.AddJsonFile($"appsettings.{environmentName}.json", true); config.AddEnvironmentVariables(); }) .UseServiceProviderFactory(new WindsorServiceProviderFactory()) .ConfigureContainer <WindsorContainer>( (hostBuilderContext, container) => { container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel)); container.AddFacility <TypedFactoryFacility>(); var rootAssembly = Application.GetRootAssembly(); container.Register( Classes .FromAssemblyInThisApplication(rootAssembly) .Pick() .Unless(x => x.GetInterfaces().Any() == false || x.IsConstructable() == false) .WithServiceAllInterfaces() .LifestyleSingleton() ); // Execute all installers in every library in the application container.Install(FromAssembly.InThisApplication(rootAssembly)); });
public static void Startup() { #pragma warning disable 618 // Create the container Container = new WindsorContainer(); // Add the Array Resolver, so we can take dependencies on T[] // while only registering T. Container.Kernel.Resolver.AddSubResolver(new ArrayResolver(Container.Kernel)); // Register the kernel and container, in case an installer needs it. Container.Register( Component.For <IKernel>().Instance(Container.Kernel), Component.For <IWindsorContainer>().Instance(Container), Component.For <IControllerFactory>().ImplementedBy <WindsorControllerFactory>() ); //IFilterProvider Container.Register( Component.For <IExceptionFilter>().ImplementedBy <JsonErrorFilterAttribute>() ); // Search for an use all installers in this application. Container.Install(FromAssembly.InThisApplication()); Container.Register(Castle.MicroKernel.Registration.Classes.FromThisAssembly() .BasedOn <IController>() .LifestyleTransient() .Configure(x => x.Named(x.Implementation.FullName))); #pragma warning restore 618 }
public static ContainerBootstrapper Bootstrap() { var container = new WindsorContainer().Install(FromAssembly.InThisApplication()); DependencyResolver.SetResolver(new WindsorDependencyResolver(container)); return(new ContainerBootstrapper(container)); }
public WindsorContainer GetContainer() { var container = new WindsorContainer(); container.Install(FromAssembly.InThisApplication()); return(container); }
private void BootstrapContainer() { WuCore.Db.Service.Ioc.container = new WindsorContainer() .Install(FromAssembly.InThisApplication()); var controllerFactory = new WindsorControllerFactory(WuCore.Db.Service.Ioc.container.Kernel); ControllerBuilder.Current.SetControllerFactory(controllerFactory); }
public static void WindsorContainer() { container = new WindsorContainer().Install(FromAssembly.InThisApplication()); var controllerFactory = new WindsorControllerFactory(container.Kernel); ControllerBuilder.Current.SetControllerFactory(controllerFactory); GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new WindsorWebApiControllerActivator(container)); }
private void Application_Startup(object sender, StartupEventArgs e) { DispatcherUnhandledException += OnDispatcherUnhandledException; _container = new WindsorContainer(); // Disable property injection var propInjector = _container.Kernel.ComponentModelBuilder .Contributors .OfType <PropertiesDependenciesModelInspector>() .Single(); _container.Kernel.ComponentModelBuilder.RemoveContributor(propInjector); _container.AddFacility <TypedFactoryFacility>(); _container.Install(FromAssembly.InThisApplication()); _container.Install(FromAssembly.Named("Filtration.Parser")); // Not directly referenced so manually call its installers Mapper.Configuration.ConstructServicesUsing(_container.Resolve); Mapper.CreateMap <ItemFilterBlockGroup, ItemFilterBlockGroupViewModel>() .ForMember(destination => destination.ChildGroups, options => options.ResolveUsing( delegate(ResolutionResult resolutionResult) { var context = resolutionResult.Context; var showAdvanced = (bool)context.Options.Items["showAdvanced"]; var group = (ItemFilterBlockGroup)context.SourceValue; if (showAdvanced) { return(group.ChildGroups); } else { return(group.ChildGroups.Where(c => c.Advanced == false)); } })) .ForMember(dest => dest.SourceBlockGroup, opts => opts.MapFrom(from => from)) .ForMember(dest => dest.IsExpanded, opts => opts.UseValue(false)); Mapper.CreateMap <Theme, IThemeEditorViewModel>().ConstructUsingServiceLocator(); Mapper.CreateMap <ThemeComponent, ThemeComponentViewModel>().ReverseMap(); Mapper.CreateMap <IThemeEditorViewModel, Theme>(); Mapper.AssertConfigurationIsValid(); var mainWindow = _container.Resolve <IMainWindow>(); mainWindow.Show(); var updateCheckService = _container.Resolve <IUpdateCheckService>(); updateCheckService.CheckForUpdates(); }
/// <summary> /// Called when the first resource (such as a page) in an ASP.NET application is requested. /// </summary> /// <remarks> /// The Application_Start method is called only one time during the life cycle of an application. You can use this /// method to perform startup tasks such as loading data into the cache and initializing static values. You should set /// only static data during application start. Do not set any instance data because it will be available only to the /// first instance of the HttpApplication class that is created. /// </remarks> protected void Application_Start() { AreaRegistration.RegisterAllAreas(); _container = new WindsorContainer(); _container.Kernel.Resolver.AddSubResolver(new ListResolver(_container.Kernel)); _container.AddFacility <TypedFactoryFacility>(); _container.AddFacility <StartableFacility>(factory => factory.DeferredStart()); _container.Install(FromAssembly.InThisApplication()); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc(); var container = new WindsorContainer(); container.Install(FromAssembly.InThisApplication(Assembly.GetEntryAssembly())); return(WindsorRegistrationHelper.CreateServiceProvider(container, services)); }
private static void BootstrapContainer() { //Database.SetInitializer<PoliticaDbContextProvider>(new DbContextInitializer()); //Database.SetInitializer<ApplicationAuditDbContextProvider>(new CreateDatabaseIfNotExists<ApplicationAuditDbContextProvider>()); container = new WindsorContainer() .Install(FromAssembly.InThisApplication()); var controllerFactory = new WindsorControllerFactory(container.Kernel); ControllerBuilder.Current.SetControllerFactory(controllerFactory); }
public static IWindsorContainer Install() { Object = new WindsorContainer().Install(FromAssembly.InThisApplication()); var controllerFactory = new WindsorControllerFactory(Object.Kernel); ControllerBuilder.Current.SetControllerFactory(controllerFactory); GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(Object.Kernel); return(Object); }
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup var container = new WindsorContainer(); container.Install(FromAssembly.InThisApplication()); Application.Add("container", container); }
private void Test1() { var container = new WindsorContainer(); container.Install(FromAssembly.InThisApplication(GetType().Assembly)); var king = container.Resolve <ILearn>(); var temp = king.SaySomeStr(); container.Dispose(); }
public virtual IWindsorContainer Create() { var container = new WindsorContainer(); container.AddFacility <StartableFacility>(f => f.DeferredStart()); container.AddFacility <TypedFactoryFacility>(); container.Install(FromAssembly.InThisApplication()); return(container); }
/// <summary> /// Initialize Windsor container /// </summary> private static void BootstrapContainer() { //Instanciate the container, and register all components defined by installers class //(implementing IWindsorInstaller) located in the current assembly _container = new WindsorContainer().Install(FromAssembly.InThisApplication()); //Instanciate our Windsor controllers factory (that overrides MVC standard controllers resolution) var controllerFactory = new WindsorControllerFactory(_container.Kernel); //Attach our custom controllers factory to MVC main engine ControllerBuilder.Current.SetControllerFactory(controllerFactory); }
public static ContainerBootstrapper Bootstrap() { //Register var container = new WindsorContainer(). Install(FromAssembly.InThisApplication()); GlobalConfiguration.Configuration.Services.Replace( typeof(IHttpControllerActivator), new WindsorCompositionRoot(container)); return(new ContainerBootstrapper(container)); }
public static IWindsorContainer BootstrapContainerDefault(IComparerSettings settings) { var container = new WindsorContainer(); container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel)); container.Kernel.AddHandlerSelector(new SqlHelperSelector(settings)); container.Kernel.AddHandlerSelector(new DatabaseObjectSelector(settings)); container.AddFacility <TypedFactoryFacility>(); container.Register(Component.For <IComparerSettings>().Instance(settings)); container.Install(FromAssembly.InThisApplication(Assembly.GetExecutingAssembly())); return(container); }
/// <summary> /// Creates the Windsor container and does all necessary registrations for the KillrVideo app. /// </summary> public static IWindsorContainer CreateContainer() { // Create container var container = new WindsorContainer(); // Add any app level registrations container.Register(Component.For <IGetEnvironmentConfiguration>().ImplementedBy <CloudConfigurationProvider>().LifestyleSingleton()); // Add installers from this and all referenced app assemblies container.Install(FromAssembly.InThisApplication()); return(container); }
private void Application_Startup(object sender, StartupEventArgs e) { _container = new WindsorContainer(); _container.AddFacility <TypedFactoryFacility>(); _container.Install(FromAssembly.InThisApplication()); _container.Install(FromAssembly.Named("Filtration.Parser")); var mainWindow = _container.Resolve <IMainWindow>(); mainWindow.Show(); }
public ServiceBootstrapper(string serverListeningOn) { this.serverListeningOn = serverListeningOn; windsorContainer = new WindsorContainer(); windsorContainer.Install(FromAssembly.InThisApplication()); var distilleryLoader = windsorContainer.Resolve <DistilleryLoader>(); var whiskyLoader = windsorContainer.Resolve <WhiskyLoader>(); distilleryLoader.LoadDistilleries(); whiskyLoader.LoadWhiskies(); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); }) .UseServiceProviderFactory(new WindsorServiceProviderFactory()) .ConfigureContainer <WindsorContainer>((hostBuilderContext, windsorContainer) => { windsorContainer.Kernel.Resolver.AddSubResolver(new CollectionResolver(windsorContainer.Kernel, true)); windsorContainer.AddFacility <TypedFactoryFacility>(); windsorContainer.Install(FromAssembly.InThisApplication(typeof(Program).Assembly)); });
/// <summary> /// Runs all installers within this assembly and wires up WebApi to use the castle windsor dependency injection container /// </summary> /// <param name="config">The HTTP configuration.</param> /// <returns> /// The dependency injection container /// </returns> private static IWindsorContainer RegisterWindsorContainer(HttpConfiguration config) { // Create the windsor container and run all installers in the application IWindsorContainer container = new WindsorContainer().Install(FromAssembly.InThisApplication()); // Wire up webapi to use the windsor resolver for dependency injection var resolver = new WindsorDependencyResolver(container.Kernel); config.DependencyResolver = resolver; GlobalConfiguration.Configuration.DependencyResolver = resolver; return(container); }