本文整理汇总了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 );
}
示例2: RequestSingleInterfaceProxyWithoutServiceInterface
public void RequestSingleInterfaceProxyWithoutServiceInterface()
{
IWindsorContainer container = new WindsorContainer();
container.AddComponent("standard.interceptor", typeof(StandardInterceptor));
container.AddComponent("useSingle", typeof(CalculatorServiceWithSingleProxyBehavior));
}
示例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);
}
}
示例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);
}
示例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>());
}
示例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);
}
示例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) );
}
示例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));
}
示例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);
}
示例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));
}
示例11: RequestSingleInterfaceProxyWithoutServiceInterface
public void RequestSingleInterfaceProxyWithoutServiceInterface()
{
var container = new WindsorContainer();
container.AddComponent("standard.interceptor", typeof(StandardInterceptor));
Assert.Throws(typeof(ComponentRegistrationException),()=>
container.AddComponent("useSingle", typeof(CalculatorServiceWithSingleProxyBehavior)));
}
示例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>());
}
示例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);
}
示例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);
}
示例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);
}