我试图为实现温莎城堡的工厂这个代码,但它抛出和异常如在这个问题上的标题。 我下面的实例文档在这里 。 PLZ指出哪里我收到错误的。
using System;
using System.Windows.Forms;
using Castle.Facilities.TypedFactory;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
namespace AsFactoryImplementation
{
interface IDummyComponnentFactory
{
IDummyComponnent creat();
void Relese(IDummyComponnent factory);
}
interface IDummyComponnent
{
void show();
}
class DummyComponnent:IDummyComponnent
{
public void show()
{
Console.WriteLine("just testing this for better performance");
}
}
class Program:WindsorContainer
{
static void Main(string[] args)
{
var container = new WindsorContainer();
container.AddFacility<TypedFactoryFacility>();
container.Register(Component.For<IDummyComponnent>().ImplementedBy<DummyComponnent>().Named("FirstConnection").LifeStyle.Transient
,Component.For<IDummyComponnentFactory>().AsFactory());
var val = container.Resolve<IDummyComponnent>();
val.show();
var val2 = container.Resolve<IDummyComponnentFactory>();
}
}
}