我想通過使用Castle IOC將記錄程序添加到Windows窗體應用程序。在Windows窗體應用程序中使用Castle Windsor
我註冊的記錄儀象下面這樣:
static class Program
{
[STAThread]
static void Main()
{
IWindsorContainer container = new WindsorContainer().Install(FromAssembly.This());
container.Register(Component.For<ICommonLogger>().ImplementedBy(typeof(CommonLogger)).LifeStyle.Singleton);
container.Kernel.Resolver.AddSubResolver(new EAE_Automation.COM.LoggerResolver(container.Kernel));
}
}
然後應用程序的另一種形式,我試圖使用記錄作爲財產,但它配備空的程序。
namespace Test.KNXManagement
{
public partial class Test: Form
{
public ICommonLogger Logger { get; set;}
public Tunneling()
{
Logger.Info("Testing.......................");
}
}
}
我想我在這裏失蹤
將'ICommonLogger'依賴項移動到'Test'表單的構造函數中,並從容器中解析此表單。這可以讓您在解析表單時發現錯誤配置。 – Steven
儘管您將Logger從私有域更改爲公共屬性,它仍然不起作用?你是如何註冊你的Test類的?如何解決? –
你試過Logger = container.Resolve();'將它添加到容器後? –
aevitas