.net 异常:ComponentActivator:无法代理AsFactoryImplementation。<;FactoryType>;
我在castle windsor中尝试了这段代码来实现工厂,但它抛出了异常,如本期标题所示。我正在仿效这些例子。请指出我错在哪里.net 异常:ComponentActivator:无法代理AsFactoryImplementation。<;FactoryType>;,.net,exception,castle-windsor,factory,.net,Exception,Castle Windsor,Factory,我在castle windsor中尝试了这段代码来实现工厂,但它抛出了异常,如本期标题所示。我正在仿效这些例子。请指出我错在哪里 using System; using System.Windows.Forms; using Castle.Facilities.TypedFactory; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; usi
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>();
}
}
使用系统;
使用System.Windows.Forms;
使用Castle.Facilities.TypedFactory;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用Castle.MicroKernel.Registration;
使用温莎城堡;
命名空间AsFactoryImplementation
{
接口IDummyComponnentFactory
{
IDummyComponnent creat();
无效释放(idummycomponent工厂);
}
接口IDummyComponent
{
void show();
}
类dummycomponent:idummcomponent
{
公开展览(
{
WriteLine(“只是为了更好的性能而测试它”);
}
}
课程名称:WindsorContainer
{
静态void Main(字符串[]参数)
{
var container=新的WindsorContainer();
container.AddFacility();
container.Register(Component.For().ImplementedBy().Named(“FirstConnection”).LifeStyle.Transient
,Component.For().AsFactory());
var val=container.Resolve();
val.show();
var val2=container.Resolve();
}
}
}内部的异常解释得不够好吗 类型
AsFactoryImplementation.IDummyComponnentFactory
对不可见
DynamicProxy。无法为不可访问的类型创建代理。
将类型设置为public或internal,并用
[组件:
InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)]
属性