【问题标题】:Castle Windsor StartableFacility does not startCastle Windsor StartableFacility 无法启动
【发布时间】:2012-11-22 15:50:55
【问题描述】:

我正在遵循以下示例(激进的旧模式):

http://docs.castleproject.org/Default.aspx?Page=Startable-Facility&NS=Windsor&AspxAutoDetectCookieSupport=1

这是我的完整源代码:

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 中测试的

我做错了什么?

【问题讨论】:

    标签: c# .net-4.0 castle-windsor


    【解决方案1】:

    我正在使用安装程序。这对我有帮助:

    container.AddFacility<StartableFacility>(f => f.DeferredTryStart());
    

    【讨论】:

      【解决方案2】:

      试试

      container.Register(Component.For<Startable>()
           .StartUsingMethod(s => s.Start)
           .StopUsingMethod(s => s.Stop);
      

      【讨论】:

      • 干杯。好像不再支持旧模式了。
      【解决方案3】:

      问题是您创建并实现了自己的IStartable 接口,而不仅仅是实现Castle.Core.IStartable

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多