public IntegrationContainer() { container = new WindsorContainer(); // allow collection injection container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel)); // disable automatic property injection container.Kernel.ComponentModelBuilder.RemoveContributor( container.Kernel.ComponentModelBuilder.Contributors.OfType <PropertiesDependenciesModelInspector>().Single()); container.Kernel.AddFacility <TypedFactoryFacility>(); //selectively install Finance.Service classes container.Install(new MappingsCreatorInstaller() //new MappingsInstaller() ); //Persistence.EF installers container.Install(FromAssembly.Containing <ModelContextFactory>()); //Core installers container.Install(FromAssembly.Containing <AppSettings>()); //Integration inplememntations container.Register(Component.For <IConnection>().ImplementedBy <IntegrationConnection>()); container.Register(Component.For <IExceptionService>().ImplementedBy <IntegrationExceptionService>()); //Create all mappings container.Resolve <MappingsCreator>(); DisplayRegistrations(); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { if (httpContext == null) { throw new ArgumentNullException("httpContext"); } // Make sure Forms authentication shows the user as authenticated if (httpContext.User.Identity.IsAuthenticated == false) { return(false); } if (Membership.GetUser() == null) { return(false); } // Retrieve a unit of work from Windsor, and determine if the user actually exists in the database var container = new WindsorContainer(); container.Install(FromAssembly.Containing <MJLAuthorizeAttribute>()); var unitOfWork = container.Resolve <IUnitOfWork>(); var user = new UserByIdQuery(unitOfWork).WithUserId((int)Membership.GetUser().ProviderUserKey).Execute(); return(user != null); }
public static WindsorContainerConfiguration Data(this WindsorContainerConfiguration config) { Trace.TraceInformation("Installing Data..."); config.Container.Install(FromAssembly.Containing <DataInstaller>()); return(config); }
public static IWindsorContainer InitializeContainer() { var container = IocHelper.Container; if (_initialised) { return(container); } container.Register( Component.For <IWindsorContainer>().Instance(container) ); container.Install( FromAssembly.Containing <UtilitiesInstaller>(), FromAssembly.Containing <ControllersInstaller>() ); var controllerFactory = new WindsorControllerFactory(container.Kernel); ControllerBuilder.Current.SetControllerFactory(controllerFactory); GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new WindsorHttpControllerActivator(container)); _initialised = true; return(container); }
public static void Register(IWindsorContainer container) { container.Install(FromAssembly.This()); container.Install(FromAssembly.Containing <Settings>()); //install data access container.Install(FromAssembly.Containing <DataInstaller>()); }
static void Main(string[] args) { try { var container = new WindsorContainer(); container.Install(FromAssembly.Containing <NHibernateConfigurationInstaller>()); Info("Creating tables..."); var cfg = container.Resolve <NHibernate.Cfg.Configuration>(); cfg.SetInterceptor(new ConsoleInterceptor()); var se = new SchemaUpdate(cfg); se.Execute(sql => { File.WriteAllText("update-database.sql", sql); }, doUpdate: true); RunMigration(); Success(" Success\r\n"); ExecuteSqlScripts(); } catch (Exception exc) { Error(exc.ToString()); } Console.Read(); }
public OGDotNetApp() { //Can't read default config directly if we're untrusted http://social.msdn.microsoft.com/Forums/en-US/clr/thread/1e14f665-10a3-426b-a75d-4e66354c5522 var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var section = config.Sections["castle"]; var configXml = section.SectionInformation.GetRawXml(); var resource = new StaticContentResource(configXml); var xmlInterpreter = new XmlInterpreter(resource); _container = new WindsorContainer(xmlInterpreter); FromAssembly.Containing <RemoteEngineContextFactory>().Install(_container, new DefaultConfigurationStore()); _container.Register(); //Give all of the windows the opportunity to pick up context var windowStyle = new Style(typeof(Window)); windowStyle.Setters.Add(new Setter(OGContextProperty, new Binding("OGContext") { Source = this })); windowStyle.Setters.Add(new Setter(OGContextFactoryProperty, new Binding("OGContextFactory") { Source = this })); FrameworkElement.StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata { DefaultValue = windowStyle } ); FreezeDetector.HookUp(Dispatcher, _container.Resolve <ILogger>()); }
protected override void ConfigureApplicationContainer(IWindsorContainer existingContainer) { base.ConfigureApplicationContainer(existingContainer); // Add the Array Resolver, so we can take dependencies on T[] // while only registering T. existingContainer.Kernel.Resolver.AddSubResolver(new ArrayResolver(existingContainer.Kernel)); var loggerInstaller = new LoggerInstaller(); loggerInstaller.Install(existingContainer, null); var loaderInstaller = new ProjectComponentLoaderInstaller(); loaderInstaller.Install(existingContainer, null); existingContainer.Install(FromAssembly.Containing(typeof(Installer))); existingContainer.Install(FromAssembly.Containing(typeof(MicroServices.Days.Nancy.Installer))); existingContainer.Install(FromAssembly.Containing(typeof(MicroServices.Doctors.Nancy.Installer))); existingContainer.Install(FromAssembly.Containing(typeof(MicroServices.DoctorsSlots.Nancy.Installer))); existingContainer.Install(FromAssembly.Containing(typeof(MicroServices.Slots.Nancy.Installer))); }
public static void Main(string[] args) { System.Console.WriteLine("Hello World"); using (var container = new WindsorContainer()) { container.Install(FromAssembly.Containing(typeof(Installer))); var converter = container.Resolve <IStringToCellInformationConverter>(); IEnumerable <ICellInformation> cells = converter.Convert(CreateStillLife()); var manager = container.Resolve <IBoardManager>(); manager.Update(cells); var converterToText = container.Resolve <ICellInformationToStringConverter>(); for (var i = 1; i <= 100; i++) { IEnumerable <string> text = converterToText.Convert(manager.LivingCells()); Display(text); manager.NextGeneration(); } container.Release(converter); container.Release(converterToText); container.Release(manager); } System.Console.ReadLine(); }
private void InitializeWindsor() { _windsorContainer = new WindsorContainer(); _windsorContainer.Install(FromAssembly.Containing <CoffeeShopDependencyInstaller>()); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(_windsorContainer.Kernel)); }
public void Implementing() { var result = FromAssembly.Containing <JustAClass>().Implementing <IAmJustAnInterface>(); Assert.Equal(1, result.Length); Assert.Equal(typeof(JustAClass), result[0]); }
public void Windsor_Can_Resolve_All_Command_And_Query_Classes() { // Setup Assembly asm = Assembly.GetAssembly(typeof(IUnitOfWork)); IList <Type> classTypes = Assembly.GetAssembly(typeof(MJLConstants)) .GetTypes() .Where(x => !x.IsDefined(typeof(CompilerGeneratedAttribute), false)) .Where(x => x.Namespace.StartsWith("MyJobLeads.DomainModel.Commands") || x.Namespace.StartsWith("MyJobLeads.DomainModel.Queries")) .Where(x => x.IsClass && !x.IsDefined(typeof(CompilerGeneratedAttribute), false)) .Distinct() .ToList(); IWindsorContainer container = new WindsorContainer(); container.Kernel.ComponentModelBuilder.AddContributor(new SingletonLifestyleEqualizer()); container.Install(FromAssembly.Containing <HomeController>()); string assertOutput = "The following types could not be resolved: " + Environment.NewLine; int failureCount = 0; // Act foreach (Type t in classTypes) { try { container.Resolve(t); } catch (ComponentNotFoundException) { assertOutput += t.FullName + Environment.NewLine; failureCount++; } } // Verify Assert.IsTrue(failureCount == 0, assertOutput + string.Format("{0} classes missing from Windsor", failureCount)); }
static Program() { Container = new WindsorContainer(); Container.Is(Perspective.Release).Is(Environmentt.Test); Container.Install(FromAssembly.Containing(typeof(Program))); Container.Install(FromAssembly.Containing(typeof(Container))); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { // Only allow access if the user is a site administrator if (Membership.GetUser() != null) { var container = new WindsorContainer(); container.Install(FromAssembly.Containing <RequiresOrganizationAdminAttribute>()); var context = container.Resolve <MyJobLeadsDbContext>(); int userId = (int)Membership.GetUser().ProviderUserKey; if (context.Users.Where(x => x.Id == userId && x.IsOrganizationAdmin).Count() > 0) { return; } } // User wasn't logged in or not an organization administrator, so redirect to the homepage filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" }, { "area", "" } }); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddCors(o => o.AddPolicy("MyPolicy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); })); var container = new WindsorContainer(); container.AddFacility <AspNetCoreFacility>(f => f.CrossWiresInto(services)); container.AddFacility <TypedFactoryFacility>(); services.AddDbContext <AppDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSignalR(); container.Install( FromAssembly.Containing <Startup>(), FromAssembly.Containing <DataAccessInstaller>()); return(services.AddWindsor(container)); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { // Only allow access if the user is a site administrator if (Membership.GetUser() != null) { var container = new WindsorContainer(); container.Install(FromAssembly.Containing <RequiresSiteAdminAttribute>()); var process = container.Resolve <IProcess <SiteAdminAuthorizationParams, AuthorizationResultViewModel> >(); int userId = (int)Membership.GetUser().ProviderUserKey; var result = process.Execute(new SiteAdminAuthorizationParams { UserId = userId }); if (result.UserAuthorized) { return; } } // User wasn't logged in or not a site administrator, so redirect to the homepage filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" }, { "area", "" } }); }
private void _RegisterComponents(WindsorContainer ioCContainer) { CoreDddNhibernateInstaller.SetUnitOfWorkLifeStyle(x => x.PerThread); ioCContainer.Install( FromAssembly.Containing <CoreDddInstaller>(), FromAssembly.Containing <CoreDddNhibernateInstaller>() ); ioCContainer.Register( Classes .FromAssemblyContaining <CreateNewShipCommand>() // register all command handlers in this assembly .BasedOn(typeof(ICommandHandler <>)) .WithService.FirstInterface() .Configure(x => x.LifestyleTransient()), Classes .FromAssemblyContaining <GetPoliciesByTermsQuery>() // register all query handlers in this assembly .BasedOn(typeof(IQueryHandler <>)) .WithService.FirstInterface() .Configure(x => x.LifestyleTransient()), Component.For <INhibernateConfigurator>() // register nhibernate configurator .ImplementedBy <CoreDddSampleNhibernateConfigurator>() .LifeStyle.Singleton, Component.For <ShipController>(), // register ship controller to get query executor and command executor injected into the constructor Component.For <PolicyHolderController>(), // register policy holder controller to get query executor and command executor injected into the constructor Component.For <PolicyController>() // register policy controller to get query executor and command executor injected into the constructor ); }
public void SetUp() { container.Install(FromAssembly.Containing <IOC.Installers.AggregateInstaller>()); container.Register( Component.For <AggregateRootTestClass>() ); _sut = container.Resolve <AggregateRootTestClass>(); }
public void Generics() { var result = FromAssembly.Containing <JustAClass>().Implementing(typeof(IAmAGenericInterface <>)); Assert.Equal(2, result.Length); Assert.True(result.Any(t => t == typeof(GenericImpel))); Assert.True(result.Any(t => t == typeof(GenericOtherImpel))); }
static IWindsorContainer ConfigureIoC() { var container = new WindsorContainer(); container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true)); container.Install(Configuration.FromAppConfig(), FromAssembly.This(), FromAssembly.Containing <GuestBookXmlProvider>()); return(container); }
/// <summary> /// Configure Windsor IOC /// </summary> /// <param name="configuration"></param> public static void ConfigureWindsor(HttpConfiguration configuration) { ContainerManager.Container.Install(FromAssembly.This()); ContainerManager.Container.Install(FromAssembly.Containing(typeof(TextProcessAppService))); var dependencyResolver = new WindsorDependencyResolver(ContainerManager.Container); configuration.DependencyResolver = dependencyResolver; }
public static ContainerBootstrapper Bootstrap() { var container = new WindsorContainer(). Install(FromAssembly.This()). Install(FromAssembly.Containing(typeof(ITranslationService))); return(new ContainerBootstrapper(container)); }
private static WindsorContainer CreateContainer() { var container = new WindsorContainer(); container.Install(FromAssembly.Containing <IOrdersRepository>()); container.AutoRegisterHandlersFromAssembly(typeof(OrderHandler).Assembly); return(container); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.AddFacility <CacheFacility>(); container.Register(Component.For <ICacheProvider>().ImplementedBy <NetCacheProvider>()); container.Register(Types.FromThisAssembly().BasedOn <IHttpController>().LifestyleTransient()); container.Install(FromAssembly.Containing(typeof(ServiceInstaller))); }
public static void Initialize() { _container = new WindsorContainer(); _container.Install(FromAssembly.This(), FromAssembly.Containing <ServiceInstaller>()); _container.Register(Component.For <IWindsorContainer>().Instance(_container).LifestyleSingleton()); }
public static WindsorContainerConfiguration System(this WindsorContainerConfiguration config) { Trace.TraceInformation("Installing System..."); config.Container.Install(FromAssembly.Containing <Settings>()); return(config); }
public static WindsorContainerConfiguration Command(this WindsorContainerConfiguration config) { Trace.TraceInformation("Installing Command..."); config.Container.Install(FromAssembly.Containing <CommandInstaller>()); return(config); }
public static void InitializeCommon(IWindsorContainer container) { container.Install(FromAssembly.This(), FromAssembly.Containing <LogicInstaller>(), FromAssembly.Containing <DataInstaller>() ); container.Register(Component.For <IWindsorContainer>().Instance(container).LifestyleSingleton()); }
private void BootstrapContainer() { container = new WindsorContainer() .Install(FromAssembly.Containing <ControllerInstaller>()); var controllerFactory = new WindsorControllerFactory(container.Kernel); ControllerBuilder.Current.SetControllerFactory(controllerFactory); }
private static IWindsorContainer InstallComponents() { var container = new WindsorContainer(); container.Install(FromAssembly.This(), FromAssembly.Containing <MessageSerializerWindsorInstaller>(), FromAssembly.Containing <ICompressor>()); return(container); }