我正在遵循以下示例(激进的旧模式):
这是我的完整源代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Castle.Facilities.Startable;
using Castle.MicroKernel;
using Castle.MicroKernel.Registration;
namespace Test
{
public interface IStartable
{
void Start();
void Stop();
}
public class Startable : IStartable
{
public Startable()
{
Console.WriteLine("Created!");
}
public void Start()
{
Console.WriteLine("Started!");
}
public void Stop()
{
Console.WriteLine("Stopped!");
}
}
[TestFixture]
public class StartableFacilityContainerTest
{
[Test]
public void TestOperation()
{
IKernel container = new DefaultKernel();
container.AddFacility<StartableFacility>();
container.Register(Component.For<Startable>());
Console.WriteLine("Registered!");
container.Dispose();
Console.WriteLine("Released!");
}
}
}
但是,当我运行它时,我得到:
Registered!
Released!
当我期望得到(如示例中所示)时:
Created!
Started!
Registered!
Stopped!
Released!
基本上我的 Startable 没有启动。
这是在 .Net 4.0 和 Castle Windsor 3.0 中测试的
我做错什么了?