Пример #1
0
        protected override void AddDependencyCore(Type dependent, Type concrete, DependencyLifetime lifetime)
        {
            string componentName = Guid.NewGuid().ToString();

            if (lifetime != DependencyLifetime.PerRequest)
            {
#if CASTLE_20
                _windsorContainer.AddComponentLifeStyle(componentName, dependent, concrete,
                                                        ConvertLifestyles.ToLifestyleType(lifetime));
#elif CASTLE_10
                _windsorContainer.AddComponentWithLifestyle(componentName, dependent, concrete, ConvertLifestyles.ToLifestyleType(lifetime));
#endif
            }
            else
            {
#if CASTLE_20
                _windsorContainer.Register(
                    Component.For(dependent).Named(componentName).ImplementedBy(concrete).LifeStyle.Custom(typeof(ContextStoreLifetime)));
#elif CASTLE_10
                ComponentModel component = _windsorContainer.Kernel.ComponentModelBuilder.BuildModel(componentName, dependent, concrete, null);
                component.LifestyleType   = ConvertLifestyles.ToLifestyleType(lifetime);
                component.CustomLifestyle = typeof(ContextStoreLifetime);
                _windsorContainer.Kernel.AddCustomComponent(component);
#endif
            }
        }
Пример #2
0
        public void Register <Interface>(Type implType)
        {
            EnsureInitialized();

            var key          = string.Format("{0}-{1}", typeof(Interface).Name, implType.FullName);
            var isRegistered = _container.Kernel.HasComponent(key);

            if (isRegistered)
            {
                return;
            }

            _container.AddComponentLifeStyle(key,
                                             typeof(Interface),
                                             implType,
                                             LifestyleType.Transient);
        }
 public void Register(IWindsorContainer container)
 {
     Assembly.GetAssembly(typeof(ControllersRegistrarMarker)).GetExportedTypes()
             .Where(IsController)
             .Each(type => container.AddComponentLifeStyle(
                                   type.Name.ToLower(),
                                   type,
                                   LifestyleType.Transient));
 }
Пример #4
0
 // Dies nur als Beispiel, besser direkt die Implementierung von http://mvccontrib.org verwenden
 private static void RegisterControllersInContainer(IWindsorContainer container)
 {
     var controllerType = from t in typeof(HomeController).Assembly.GetTypes()
                       where typeof (IController).IsAssignableFrom(t)
                       select t;
     foreach (var type in controllerType)
     {
         container.AddComponentLifeStyle(type.FullName, type, LifestyleType.Transient);
     }
 }
Пример #5
0
        public static IWindsorContainer RegisterControllers(this IWindsorContainer container, params Type[] controllerTypes)
        {
            foreach (var type in controllerTypes)
            {
                if (ControllerExtensions.IsController(type))
                {
                    container.AddComponentLifeStyle(type.FullName.ToLower(), type, LifestyleType.Transient);
                }
            }

            return(container);
        }
Пример #6
0
        public static IWindsorContainer RegisterQuartzJobs(this IWindsorContainer container, params Type[] jobTypes)
        {
            foreach (var type in jobTypes)
            {
                if (JobExtensions.IsJob(type))
                {
                    container.AddComponentLifeStyle(type.FullName.ToLower(), type, LifestyleType.Transient);
                }
            }

            return(container);
        }
Пример #7
0
 private static void RegisterTypesInContainer(IWindsorContainer container)
 {
     RegisterControllersInContainer(container);
     container.AddComponentLifeStyle<ICustomerRepository, CustomerRepository>(LifestyleType.Transient);
     container.AddComponentLifeStyle<IOrderRepository, OrderRepository>(LifestyleType.Transient);
     container.AddComponentLifeStyle<ICustomerService, CustomerService>(LifestyleType.Transient);
     container.AddComponentLifeStyle<IOrderService, OrderService>(LifestyleType.Transient);
     container.AddComponentLifeStyle<ICustomerMapper, CustomerMapper>(LifestyleType.Singleton);
     container.AddComponentLifeStyle<IOrderMapper, OrderMapper>(LifestyleType.Singleton);
 }
        // The constructor:
        // 1. Sets up a new IoC container
        // 2. Registers all components specified in web.config
        // 3. Registers all controller types as components
        public WindsorControllerFactory()
        {
            // Instantiate a container, taking configuration from web.config
            container = WindsorContainerProvider.Instance();

            // Also register all the controller types as transient
            var controllerTypes =
                from t in Assembly.GetExecutingAssembly().GetTypes()
                where typeof(IController).IsAssignableFrom(t)
                select t;

            foreach (Type t in controllerTypes)
            {
                container.AddComponentLifeStyle(t.FullName, t, LifestyleType.Transient);
            }
        }
Пример #9
0
        public static void Configure(IWindsorContainer container)
        {
            //allows us to take a dependency on arrays
            container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));

            //
            container.AddComponent<Dispatcher>("dispatcher");

            //argument parsing

            container.AddComponentLifeStyle<IArgumentParser, ArgumentParser>("argumentParser", LifestyleType.Transient);
            container.AddComponentLifeStyle<IArgumentMapFactory, ArgumentMapFactory>("argumentMapFactory", LifestyleType.Transient);

            //helper shims
            container.AddComponentLifeStyle<IConsole, ConsoleHelper>("consoleHelper", LifestyleType.Transient);
            container.AddComponentLifeStyle<IPath, PathAdapter>("pathAdapter", LifestyleType.Transient);
            container.AddComponentLifeStyle<IFileSystem, FileSystem>("fileSystem", LifestyleType.Transient);

            //templating
            container.AddComponentLifeStyle<ITemplateProcessor, NVelocityTemplateProcessor>("templateProcessor",
                                                                                                LifestyleType.Transient);

            //package repository
            container.AddComponent<IPackageRepository, LocalPackageRepository>("package.repository");

            //project stuff
            container.AddComponentLifeStyle<IProjectManifestStore, XmlProjectManifestStore>("xmlProjectStore", LifestyleType.Transient);
            container.AddComponentLifeStyle<IProjectManifestRepository, ProjectManifestRepository>("projectManifestRepository", LifestyleType.Transient);

            //default package commands
            container.AddComponent<ICommand, HelpCommand>("help");
            container.Register(
                Component.For<ICommand>().ImplementedBy<NewProjectCommand>()
                .Named("project")
                .Parameters(
                    Parameter.ForKey("rootTemplateDirectory").Eq("a"), //TODO: correct this
                    Parameter.ForKey("defaultTemplate").Eq("b"))); //TODO: Correct this

            SetupNewProject(container);
            container.AddComponent<ICommand, ListCommand>("list");
            container.AddComponent<ICommand, InstallCommand>("install");
        }
Пример #10
0
        private static void SetupNewProject(IWindsorContainer container)
        {
            container.AddComponentLifeStyle<ITransformationElement,FolderTransformationElement>("folderTransformation",
                                            LifestyleType.Transient);

            container.AddComponentLifeStyle<ITransformationElement,FileTransformationElement>("fileTransformation", LifestyleType.Transient);

            container.AddComponentLifeStyle<IProjectTransformationPipeline,ProjectTransformationPipeline>("transformationPipeline", LifestyleType.Transient);
        }
Пример #11
0
 public static DependencyAdder Register <Interface, Implementation>(string key, LifestyleType lifestyleType)
 {
     EnsureInitialized();
     _container.AddComponentLifeStyle(key, typeof(Interface), typeof(Implementation), lifestyleType);
     return(new DependencyAdder(key, _container.Kernel));
 }
Пример #12
0
        private static void RegisterRepositories(IWindsorContainer container)
        {
            IEnumerable<Type> repositories = Assembly.GetExecutingAssembly().
                GetTypes().Where(IsRepository);

            foreach (Type repository in repositories)
            {
                container.AddComponentLifeStyle(repository.Name, repository,
                  LifestyleType.Transient);
            }
        }
Пример #13
0
        public void RegisterComponents(IWindsorContainer container)
        {
            container.AddComponentLifeStyle("newscontroller", typeof(NewsController), LifestyleType.Transient);

            container.AddComponent("News", typeof(Tags.News));
        }
Пример #14
0
        /// <summary>
        /// Configures the container with the provided components.
        /// </summary>
        /// <param name="components">The components.</param>
        public void ConfigureWith(IEnumerable <ComponentInfo> components)
        {
            foreach (var info in components)
            {
                switch (info.Lifetime)
                {
                case ComponentLifetime.Singleton:
                    if (string.IsNullOrEmpty(info.Key))
                    {
                        _container.Register(
                            Component.For(info.Service).ImplementedBy(info.Implementation).LifeStyle.Singleton
                            );
                    }
                    else if (info.Service == null)
                    {
                        _container.AddComponentLifeStyle(info.Key, info.Implementation, LifestyleType.Singleton);
                    }
                    else
                    {
                        _container.AddComponentLifeStyle(info.Key, info.Service, info.Implementation,
                                                         LifestyleType.Singleton);
                    }
                    break;

                case ComponentLifetime.Custom:
                {
                    if (!string.IsNullOrEmpty(info.Key))
                    {
                        throw new NotSupportedException();
                    }

                    var method = typeof(LifestyleGroup <object>).GetMethod(
                        "Custom",
                        new[] { typeof(ILifestyleManager) }
                        );

                    var genericMethod = method.MakeGenericMethod(info.CustomLifetimeType);

                    var lifestyle = Component.For(info.Service).ImplementedBy(info.Implementation).LifeStyle;
                    _container.Register(
                        (ComponentRegistration <object>)genericMethod.Invoke(lifestyle, new object[0]));
                }
                break;

                case ComponentLifetime.PerRequest:
                    if (string.IsNullOrEmpty(info.Key))
                    {
                        _container.Register(
                            Component.For(info.Service).ImplementedBy(info.Implementation).LifeStyle.Transient
                            );
                    }
                    else if (info.Service == null)
                    {
                        _container.AddComponentLifeStyle(info.Key, info.Implementation, LifestyleType.Transient);
                    }
                    else
                    {
                        _container.AddComponentLifeStyle(info.Key, info.Service, info.Implementation, LifestyleType.Transient);
                    }
                    break;

                default:
                    throw new NotSupportedException(
                              string.Format("{0} is not supported in Windsor.", info.Lifetime)
                              );
                }
            }
        }
 public void RegisterImplementationOf(string id, Type service, Type implementation, LifeStyle lifeStyle)
 {
     underlyingContainer.AddComponentLifeStyle(id, service, implementation, lifeStyleTranslation[lifeStyle]);
 }
Пример #16
0
        void IContainer.RegisterComponent(string key, Type classType, ComponentLifestyle componentLifestyle)
        {
            LifestyleType lifestyleType = GetLifestyleType(componentLifestyle);

            _container.AddComponentLifeStyle(key, classType, lifestyleType);
        }
 public void Install(IWindsorContainer container, IConfigurationStore store)
 {
     container.AddComponentLifeStyle<TwitterContext>(LifestyleType.Singleton);
 }
Пример #18
0
        protected void Application_Start(object sender, EventArgs e)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo(Server.MapPath("/log4net.config")));
            GlobalLog = LogManager.GetLogger(typeof (Global));
            GlobalLog.Debug("Application_Start");
            container = new WindsorContainer();
            container.AddComponentLifeStyle<Service>(LifestyleType.Transient);
            container.AddFacility<FactorySupportFacility>();
            container.Register(Component.For<IHttpModule>()
                                   .ImplementedBy<UserHttpModule>()
                                   .LifeStyle.Custom<PerHttpApplicationLifestyleManager>());
            container.Register(Component.For<IHttpModule>()
                                   .ImplementedBy<UserHttpModule2>()
                                   .LifeStyle.Custom<PerHttpApplicationLifestyleManager>());

            container.Register(Component.For<HttpRequestBase>()
                .LifeStyle.PerWebRequest
                .UsingFactoryMethod(() => new HttpRequestWrapper(HttpContext.Current.Request)));

            container.Register(Component.For<HttpContextBase>()
                .LifeStyle.PerWebRequest
                .UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
        }
Пример #19
0
 private static void RegisterGateways(IWindsorContainer container)
 {
     container.AddComponentLifeStyle("bloggerGateway",
     typeof(BloggerGateway), LifestyleType.Transient);
 }