当前位置: 首页>>代码示例>>C#>>正文


C# WindsorContainer.AddComponent方法代码示例

本文整理汇总了C#中WindsorContainer.AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# WindsorContainer.AddComponent方法的具体用法?C# WindsorContainer.AddComponent怎么用?C# WindsorContainer.AddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WindsorContainer的用法示例。


在下文中一共展示了WindsorContainer.AddComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExternalConfigurationUsage

		public void ExternalConfigurationUsage()
		{
			WindsorContainer container = new WindsorContainer( ConfigHelper.ResolvePath("../aop_castle_config.xml") );

			container.AddFacility( "aspectsharp", new AspectSharpFacility() );
			
			// Logger implementation
			container.AddComponent( "logger", typeof(ILogger), typeof(MemoryLogger) );

			// AopAlliance interceptors
			container.AddComponent( "log4netinterceptor", typeof(LoggerTraceInterceptor) );
			
			// Protocol handlers
			container.AddComponent( "protocolhandler.miranda", 
				typeof(IProtocolHandler), typeof(MirandaProtocolHandler) );
			container.AddComponent( "protocolhandler.messenger", 
				typeof(IProtocolHandler), typeof(MessengerProtocolHandler) );
			
			// using...

			ILogger logger = (ILogger) container[ typeof(ILogger) ];
			Assert.AreEqual( 0, logger.Contents.Length );

			IProtocolHandler handler = (IProtocolHandler) 
				container[ "protocolhandler.miranda" ];
			handler.Handle( "contents" );

			handler = (IProtocolHandler) container[ "protocolhandler.messenger" ];
			handler.Handle( "contents" );

			Assert.AreEqual( "Entering Handle Leaving Handle Entering Handle Leaving Handle ", 
				logger.Contents );
		}
开发者ID:atczyc,项目名称:castle,代码行数:33,代码来源:ExternalConfigurationTestCase.cs

示例2: RequestSingleInterfaceProxyWithoutServiceInterface

		public void RequestSingleInterfaceProxyWithoutServiceInterface()
		{
			IWindsorContainer container = new WindsorContainer();

			container.AddComponent("standard.interceptor", typeof(StandardInterceptor));
			container.AddComponent("useSingle", typeof(CalculatorServiceWithSingleProxyBehavior));
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:7,代码来源:ProxyBehaviorInvalidTestCase.cs

示例3: Main

        static void Main()
        {
            try
            {
                ConfigureDatabase();

                IWindsorContainer container = new WindsorContainer();
                container.AddComponent("logger",typeof(ILogger), typeof(ConsoleLoggerImpl));
                container.AddComponent("auditor", typeof (IAuditor), typeof (AuditorImpl));
                container.AddComponent("authorization", typeof (IAuthorization), typeof (AuthorizationImpl));
                container.AddComponent("repository", typeof(IRepository), typeof(RepositoryImpl));
                container.AddComponent("customer_finder", typeof (ICustomerFinder), typeof (CustomerFinderImpl));

                ICustomerFinder customerFinder = container.Resolve<ICustomerFinder>();
                ICollection<Customer> customers = customerFinder.FindCustomersByName("oren");
                foreach (Customer customer in customers)
                {
                    Console.WriteLine("Got customer: "+customer.Name);
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
        }
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:25,代码来源:Program.cs

示例4: Main

		private static void Main(string[] args)
		{
			XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.xml"));

			var cfg = RunnerConfigurator.New(c =>
				{
					c.SetServiceName("PostalService");
					c.SetDisplayName("Sample Email Service");
					c.SetDescription("we goin' postal");

					c.RunAsLocalSystem();
					c.DependencyOnMsmq();

					c.BeforeStartingServices(a =>
						{
							var container = new WindsorContainer("postal-castle.xml");
							container.AddComponent<SendEmailConsumer>("sec");
							container.AddComponent<PostalService>();
						});

					c.ConfigureService<PostalService>(a =>
						{
							a.WhenStarted(o => o.Start());
							a.WhenStopped(o => o.Stop());
						});
				});
			Runner.Host(cfg, args);
		}
开发者ID:rajwilkhu,项目名称:MassTransit,代码行数:28,代码来源:Program.cs

示例5: ConfigureIoC

        public void ConfigureIoC()
        {
            // create a Windsor container with various component parameters established
            var container = new WindsorContainer(Server.MapPath("~/castle.config"));

            // Replaces the default IViewEngine.
            container.AddComponent<IViewEngine, SparkViewFactory>();
            container.AddComponent<IViewActivatorFactory, WindsorViewActivator>();

            // Add anything descended from IController/Controller
            container.Register(
                AllTypes.Of<IController>()
                    .FromAssembly(typeof (Global).Assembly)
                    .Configure(c => c.LifeStyle.Transient.Named(c.Implementation.Name.ToLowerInvariant())));

            // Some more components from the sample
            container.AddComponent<IViewFolder, FileSystemViewFolder>();
            container.AddComponent<ISampleRepository, SampleRepository>();
            container.AddComponent<INavRepository, NavRepository>();

            // Place this container as the dependency resolver and hook it into
            // the controller factory mechanism
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container.Kernel));
            ViewEngines.Engines.Add(container.Resolve<IViewEngine>());
        }
开发者ID:dtabuenc,项目名称:spark,代码行数:25,代码来源:Global.cs

示例6: TestBasicOperations

		public void TestBasicOperations()
		{
			WindsorContainer container = new WindsorContainer(new DefaultConfigurationStore());

			container.AddFacility("transactionmanagement", new TransactionFacility());

			container.AddComponent("transactionmanager",
								   typeof(ITransactionManager), typeof(MockTransactionManager));

			container.AddComponent("services.customer", typeof(CustomerService));

			CustomerService service = (CustomerService)container["services.customer"];

			service.Insert("TestCustomer", "Rua P Leite, 33");

			MockTransactionManager transactionManager = (MockTransactionManager)
														container["transactionmanager"];

			Assert.AreEqual(1, transactionManager.TransactionCount);
			Assert.AreEqual(1, transactionManager.CommittedCount);
			Assert.AreEqual(0, transactionManager.RolledBackCount);

			try
			{
				service.Delete(1);
			}
			catch (Exception)
			{
				// Expected
			}

			Assert.AreEqual(2, transactionManager.TransactionCount);
			Assert.AreEqual(1, transactionManager.CommittedCount);
			Assert.AreEqual(1, transactionManager.RolledBackCount);
		}
开发者ID:ralescano,项目名称:castle,代码行数:35,代码来源:TransactionTestCase.cs

示例7: AddFiltersAndControllers

		private void AddFiltersAndControllers(WindsorContainer container)
		{
			container.AddComponent( "auth.filter", typeof(CheckAuthenticationFilter) );
			container.AddComponent( "home", typeof(HomeController) );
			container.AddComponent( "dashboard", typeof(DashboardController) );
			container.AddComponent( "registration", typeof(RegistrationController) );
			container.AddComponent( "project", typeof(ProjectController) );
		}
开发者ID:ralescano,项目名称:castle,代码行数:8,代码来源:PestControlApplication.cs

示例8: Init

 public static void Init() {
     IWindsorContainer container = new WindsorContainer();
     container.AddComponent("validator", 
         typeof(IValidator), typeof(Validator));
     container.AddComponent("entityDuplicateChecker",
         typeof(IEntityDuplicateChecker), typeof(EntityDuplicateCheckerStub));
     ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
 }
开发者ID:EdisonCP,项目名称:sharp-architecture,代码行数:8,代码来源:ServiceLocatorInitializer.cs

示例9: Windsor_FS

 public void Windsor_FS()
 {
     var container = new WindsorContainer();
     container.AddComponent<TestInterceptor>();
     container.Kernel.ProxyFactory.AddInterceptorSelector(new TestInterceptorSelector());
     container.AddComponent<IComparer, ComparerFS>();
     container.Resolve<IComparer>().Compare(0, 0);
 }
开发者ID:ruanzx,项目名称:mausch,代码行数:8,代码来源:ProxyTests.cs

示例10: Init

 public static void Init(Type transactionManagerType)
 {
     IWindsorContainer container = new WindsorContainer();
     container.AddComponent("TransactionManager", typeof (ITransactionManager),
                            transactionManagerType);
     container.AddComponent("ExceptionLogger", typeof (IExceptionLogger), typeof (ExceptionLogger));
     ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
 }
开发者ID:adisD,项目名称:Sharp-Architecture-Contrib,代码行数:8,代码来源:ServiceLocatorInitializer.cs

示例11: RequestSingleInterfaceProxyWithoutServiceInterface

		public void RequestSingleInterfaceProxyWithoutServiceInterface()
		{
			var container = new WindsorContainer();
			container.AddComponent("standard.interceptor", typeof(StandardInterceptor));

			Assert.Throws(typeof(ComponentRegistrationException),()=>
				container.AddComponent("useSingle", typeof(CalculatorServiceWithSingleProxyBehavior)));
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:8,代码来源:ProxyBehaviorInvalidTestCase.cs

示例12: ResolvingComponentIsDoneOnFirstComeBasisWhenNamesAreNotOrdered

		public void ResolvingComponentIsDoneOnFirstComeBasisWhenNamesAreNotOrdered()
		{
			var windsor = new WindsorContainer();
			windsor.AddComponent<IService, Srv1>("3");
			windsor.AddComponent<IService, Srv1>("2");

			Assert.IsInstanceOf<Srv1>(windsor.Resolve<IService>());
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:8,代码来源:RegisteringTwoServicesForSameType.cs

示例13: CreateServiceLocator

        protected override IServiceLocator CreateServiceLocator() {
            var container = new WindsorContainer();
            Type simpleType = typeof(SimpleLogger);
            Type complexType = typeof(ComplexLogger);
            container.AddComponent(simpleType.FullName, typeof(ILogger), simpleType);
            container.AddComponent(complexType.FullName, typeof(ComplexLogger), complexType);

            return new WindsorServiceLocator(container);
        }
开发者ID:calebjenkins,项目名称:mvcturbine,代码行数:9,代码来源:WindsorResolutionTests.cs

示例14: WillIgnoreComponentsThatAreAlreadyInTheDependencyTracker_Constructor

        public void WillIgnoreComponentsThatAreAlreadyInTheDependencyTracker_Constructor()
        {
            IWindsorContainer container = new WindsorContainer();
            container.AddComponent("chain", typeof(IChain), typeof(MyChain));
            container.AddComponent("chain2", typeof(IChain), typeof(MyChain2));

            IChain resolve = container.Resolve<IChain>("chain2");
            Assert.IsNotNull(resolve);
        }
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:9,代码来源:IoC-78.cs

示例15: ShouldNotSetTheViewControllerProperty

		public void ShouldNotSetTheViewControllerProperty()
		{
			IWindsorContainer container = new WindsorContainer();
			container.AddComponent("controller", typeof(IController), typeof(Controller));
			container.AddComponent("view", typeof(IView), typeof(View));
			Controller controller = (Controller)container.Resolve("controller");
			Assert.IsNotNull(controller.View);
			Assert.IsNull(controller.View.Controller);
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:9,代码来源:CircularDependencyTests.cs


注:本文中的WindsorContainer.AddComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。