【发布时间】:2011-09-28 21:12:46
【问题描述】:
我刚刚开始使用 Castle Windsor IoC,我很难按照示例进行操作。有人可以解释为什么这个简单的控制台应用程序失败了吗?我一定错过了一些简单的东西。谢谢。
using System;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Castle.Windsor.Installer;
namespace CastleTest
{
public interface ISomething
{
void DoSomething();
}
public class Something : ISomething
{
public void DoSomething()
{
Console.WriteLine("Hello World");
}
}
public class SomethingInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(AllTypes.FromThisAssembly().BasedOn<ISomething>());
}
}
class Program
{
static void Main()
{
using (var container = new WindsorContainer())
{
container.Install(FromAssembly.This());
// the following line throws a ComponentNotFoundException
var something = container.Resolve<ISomething>();
something.DoSomething();
}
}
}
}
【问题讨论】:
标签: c# .net castle-windsor ioc-container