public void InitializeLifecycle()
        {
            kernel.AddComponent("a", typeof(HttpFakeServer));
            HttpFakeServer server = (HttpFakeServer)kernel["a"];

            Assert.IsTrue(server.IsInitialized);
        }
		public void Init()
		{
			kernel = new DefaultKernel();
			kernel.AddComponent("compa", typeof(CompA));
			kernel.AddComponent("compb", typeof(CompB));

			deps = new Hashtable();
			deps.Add("cc", new CompC(12));
			deps.Add("myArgument", "ernst");
		}
        public void ValidSituation()
        {
            kernel.AddComponent("a", typeof(A));
            kernel.AddComponent("b", typeof(B));
            kernel.AddComponent("c", typeof(C));

            Assert.IsNotNull(kernel["a"]);
            Assert.IsNotNull(kernel["b"]);
            Assert.IsNotNull(kernel["c"]);
        }
		public void Init()
		{
			kernel = new DefaultKernel();
			kernel.AddComponent("compa", typeof(CompA));
			kernel.AddComponent("compb", typeof(CompB));

			deps = new Dictionary<string, object>();
			deps.Add("cc", new CompC(12));
			deps.Add("myArgument", "ernst");
		}
Example #5
0
        private void RegisterPresenters(Assembly assembly)
        {
            IEnumerable <Type> allPresenters = assembly.GetTypes().Where(t => typeof(IPresenter).IsAssignableFrom(t));

            foreach (Type presenterType in allPresenters)
            {
                if (_kernel.HasComponent(presenterType))
                {
                    _kernel.AddComponent("presenter." + presenterType.FullName, presenterType);
                }
            }
        }
        public void Init(IKernel kernel, IConfiguration facilityConfig)
        {
            kernel.AddComponent("transactionmanager",
                                typeof(ITransactionManager), typeof(DefaultTransactionManager));
            kernel.AddComponent("transaction.interceptor",
                                typeof(TransactionInterceptor));
            kernel.AddComponent("transaction.configholder", typeof(TransactionConfigHolder));

            _transactionConfigHolder =
                kernel[typeof(TransactionConfigHolder)] as TransactionConfigHolder;

            kernel.ComponentModelCreated += new ComponentModelDelegate(OnModelCreated);
        }
Example #7
0
		public void Init(IKernel kernel, IConfiguration facilityConfig)
		{
			kernel.AddComponent( "transactionmanager", 
				typeof(ITransactionManager), typeof(DefaultTransactionManager) );
			kernel.AddComponent( "transaction.interceptor", 
				typeof(TransactionInterceptor) );
			kernel.AddComponent( "transaction.configholder", typeof(TransactionConfigHolder) );

			_transactionConfigHolder = 
				kernel[ typeof(TransactionConfigHolder) ] as TransactionConfigHolder;

			kernel.ComponentModelCreated += new ComponentModelDelegate(OnModelCreated);
		}
        public void RemoteAccessToComponentGraph()
        {
            AppDomain current = AppDomain.CurrentDomain;

            AppDomain otherDomain = AppDomain.CreateDomain(
                "other", new Evidence(current.Evidence), current.SetupInformation);

            try
            {
                IKernel kernel = (IKernel)
                                 otherDomain.CreateInstanceAndUnwrap(
                    "Castle.MicroKernel", "Castle.MicroKernel.DefaultKernel");

                kernel.AddComponent("key", typeof(CustomerImpl));
                Assert.IsTrue(kernel.HasComponent("key"));

                GraphNode[] nodes = kernel.GraphNodes;

                Assert.IsNotNull(nodes);
                Assert.AreEqual(1, nodes.Length);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                AppDomain.Unload(otherDomain);
            }
        }
Example #9
0
 public void CreateObjects()
 {
     _kernel = new DefaultKernel();
     foreach (Type type in _classes)
     {
         _kernel.AddComponent(type.ToString(), type);
     }
 }
Example #10
0
        public void DependenciesSatisfiedAmongContainers()
        {
            IKernel subkernel = new DefaultKernel();

            kernel.AddComponent("mailsender", typeof(DefaultMailSenderService));
            kernel.AddComponent("templateengine", typeof(DefaultTemplateEngine));

            kernel.AddChildKernel(subkernel);

            subkernel.AddComponent("spamservice", typeof(DefaultSpamService));

            DefaultSpamService spamservice = (DefaultSpamService)subkernel["spamservice"];

            Assert.IsNotNull(spamservice);
            Assert.IsNotNull(spamservice.MailSender);
            Assert.IsNotNull(spamservice.TemplateEngine);
        }
		public void Init(IKernel kernel, IConfiguration config)
		{
			kernel.AddComponent("managed.dispatcher.interceptor", typeof());

			_connector = MConnectorFactory.CreateConnector( "provider:http:binary:test.rem", null );

			kernel.ComponentModelBuilder.AddContributor( new Client.ManagementExtensionModelClientInspector() );
		}
 public void CreateObjects()
 {
     _kernel = new DefaultKernel();
     foreach (Type type in _classes)
     {
         _kernel.AddComponent(type.ToString(), type);
     }
 }
Example #13
0
        public void Init(IKernel kernel, IConfiguration config)
        {
            kernel.AddComponent("managed.dispatcher.interceptor", typeof());

            _connector = MConnectorFactory.CreateConnector("provider:http:binary:test.rem", null);

            kernel.ComponentModelBuilder.AddContributor(new Client.ManagementExtensionModelClientInspector());
        }
        public void ResolvingPrimitivesThroughProperties()
        {
            MutableConfiguration config = new MutableConfiguration("component");

            MutableConfiguration parameters = (MutableConfiguration )
                                              config.Children.Add(new MutableConfiguration("parameters"));

            parameters.Children.Add(new MutableConfiguration("name", "hammett"));
            parameters.Children.Add(new MutableConfiguration("address", "something"));
            parameters.Children.Add(new MutableConfiguration("age", "25"));

            kernel.ConfigurationStore.AddComponentConfiguration("customer", config);

            kernel.AddComponent("customer", typeof(ICustomer), typeof(CustomerImpl));

            expectedClient = kernel.GetHandler("customer").ComponentModel;
            expectedModels = new ArrayList();
            foreach (PropertySet prop in kernel.GetHandler("customer").ComponentModel.Properties)
            {
                expectedModels.Add(prop.Dependency);
            }

            ICustomer customer = (ICustomer)kernel["customer"];

            Assert.IsNotNull(customer);
        }
Example #15
0
        public void TestTransient()
        {
            m_kernel.AddComponent("a", typeof(IComponent), typeof(TransientComponent));

            IHandler handler = m_kernel.GetHandler("a");

            IComponent instance1 = handler.Resolve() as IComponent;
            IComponent instance2 = handler.Resolve() as IComponent;

            Assert.IsNotNull(instance1);
            Assert.IsNotNull(instance2);

            Assert.IsTrue(!instance1.Equals(instance2));
            Assert.IsTrue(instance1.ID != instance2.ID);

            handler.Release(instance1);
            handler.Release(instance2);
        }
Example #16
0
 public void CreateObjects()
 {
     _kernel = new DefaultKernel();
     foreach (Type type in _classes)
     {
         _kernel.AddComponent(type.ToString(), type);
         log.DebugFormat("Creating instance of type <{0}>.", type);
     }
 }
Example #17
0
        public void Init(IKernel kernel, IConfiguration facilityConfig)
        {
            kernel.AddComponent("rails.controllertree", typeof(ControllerTree));

            _tree = (ControllerTree)kernel["rails.controllertree"];

            kernel.ComponentModelCreated += new ComponentModelDelegate(OnComponentModelCreated);

            AddBuitInControllers(kernel);
        }
Example #18
0
        public void Init(IKernel kernel, IConfiguration facilityConfig)
        {
            kernel.Register(
                Component.For <IParameterInterceptor>()
                .ImplementedBy <NotNullParameterInterceptor>(),
                Component.For <IParameterInterceptor>()
                .ImplementedBy <NotNullOrEmptyParameterInterceptor>());

            kernel.AddComponent("preconditions.interceptor", typeof(ParameterInterceptor));
            kernel.ComponentModelBuilder.AddContributor(new ParameterInterceptorContributor());
        }
Example #19
0
        /// <summary>
        /// Registers this instance.
        /// </summary>
        public void Register(Component component)
        {
            IKernel kernel = Kernel;

            kernel.AddComponent(component.Name, component.Service, component.Impl,
                                EnumAdapter.GetEnumValue <LifestyleType>(component.Scope));


            IHandler handler = kernel.GetHandler(component.Name);

            handler.ComponentModel.LifestyleType = EnumAdapter.GetEnumValue <LifestyleType>(component.Scope);

            kernel.RegisterCustomDependencies(component.Name, component.Parameters);

            foreach (KeyValuePair <string, string> pair in component.References)
            {
                handler.ComponentModel.Parameters.Add(pair.Key, pair.Value);
            }
        }
		public void Multithreaded()
		{
			_kernel = new DefaultKernel();
			_kernel.AddComponent("a", typeof(PoolableComponent1));

			const int threadCount = 15;

			Thread[] threads = new Thread[threadCount];

			for(int i = 0; i < threadCount; i++)
			{
				threads[i] = new Thread(new ThreadStart(ExecuteMethodUntilSignal));
				threads[i].Start();
			}

			_startEvent.Set();

			Thread.CurrentThread.Join(3 * 1000);

			_stopEvent.Set();
		}
        public void Multithreaded()
        {
            _kernel = new DefaultKernel();
            _kernel.AddComponent("a", typeof(PoolableComponent1));

            const int threadCount = 15;

            Thread[] threads = new Thread[threadCount];

            for (int i = 0; i < threadCount; i++)
            {
                threads[i] = new Thread(new ThreadStart(ExecuteMethodUntilSignal));
                threads[i].Start();
            }

            _startEvent.Set();

            Thread.CurrentThread.Join(3 * 1000);

            _stopEvent.Set();
        }
        public void TopologicalSortOnComponents()
        {
            kernel.AddComponent("a", typeof(A));
            kernel.AddComponent("b", typeof(B));
            kernel.AddComponent("c", typeof(C));

            GraphNode[] nodes = kernel.GraphNodes;

            Assert.IsNotNull(nodes);
            Assert.AreEqual(3, nodes.Length);

            IVertex[] vertices = TopologicalSortAlgo.Sort(nodes);

            Assert.AreEqual("c", (vertices[0] as ComponentModel).Name);
            Assert.AreEqual("b", (vertices[1] as ComponentModel).Name);
            Assert.AreEqual("a", (vertices[2] as ComponentModel).Name);
        }
 public void UnsatisfiedService()
 {
     kernel.AddComponent("key", typeof(CommonServiceUser));
     object instance = kernel["key"];
 }
Example #24
0
        public void ResolvingPrimitivesThroughProperties()
        {
            MutableConfiguration config = new MutableConfiguration("component");

            MutableConfiguration parameters = (MutableConfiguration )
                                              config.Children.Add(new MutableConfiguration("parameters"));

            parameters.Children.Add(new MutableConfiguration("name", "hammett"));
            parameters.Children.Add(new MutableConfiguration("address", "something"));
            parameters.Children.Add(new MutableConfiguration("age", "25"));

            kernel.ConfigurationStore.AddComponentConfiguration("customer", config);

            kernel.AddComponent("customer", typeof(ICustomer), typeof(CustomerImpl));

            ICustomer customer = (ICustomer)kernel["customer"];

            Assert.IsNotNull(customer);
            Assert.AreEqual("hammett", customer.Name);
            Assert.AreEqual("something", customer.Address);
            Assert.AreEqual(25, customer.Age);
        }
 public void ConstructorWithUnsatisfiedParameters()
 {
     kernel.AddComponent("key", typeof(ClassWithConstructors));
     object res = kernel["key"];
 }
Example #26
0
 public virtual IWindsorContainer AddComponent(String key, Type classType)
 {
     kernel.AddComponent(key, classType);
     return(this);
 }
Example #27
0
 protected virtual void AddBuitInControllers(IKernel kernel)
 {
     kernel.AddComponent("files", typeof(FilesController), typeof(FilesController));
 }
        public void ConstructorWithMoreArguments()
        {
            kernel.AddComponent("a", typeof(A));
            kernel.AddComponent("b", typeof(B));
            kernel.AddComponent("c", typeof(C));
            kernel.AddComponent("service", typeof(ServiceUser));

            ServiceUser service = (ServiceUser)kernel["service"];

            Assert.IsNotNull(service);
            Assert.IsNotNull(service.AComponent);
            Assert.IsNotNull(service.BComponent);
            Assert.IsNotNull(service.CComponent);
        }
 public ServiceLocatorStub AddService <TService, TImplementor>()
 {
     kernel.AddComponent(typeof(TService).Name, typeof(TService), typeof(TImplementor));
     return(this);
 }
Example #30
0
 [SetUp] public void Setup()
 {
     kernel.AddComponent("key", typeof(IEmailSender), typeof(MockSecureSender));
 }
Example #31
0
 public IViewActivator Register(Type type)
 {
     kernel.AddComponent(type.FullName, typeof(ISparkView), type, LifestyleType.Transient);
     return(this);
 }
 public void AddClassComponentWithInterface()
 {
     kernel.AddComponent("key", typeof(CustomerImpl));
     Assert.IsTrue(kernel.HasComponent("key"));
 }
 /// <summary>
 /// Adds a component to be managed by the container
 /// </summary>
 /// <param name="key"></param>
 /// <param name="classType"></param>
 public virtual void AddComponent(String key, Type classType)
 {
     _kernel.AddComponent(key, classType);
 }
Example #34
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public TransactionalFileService(IKernel kernel)
 {
     _kernel = kernel;
     _kernel.AddComponent("core.fileservice.transactionmanager", typeof(ITransactionManager),
                          typeof(FileTransactionManager));
 }