例外:ComponentActivator:无法代理AsFactoryImplementation.<FactoryType>

Ram*_*rna 2 .net factory castle-windsor exception

我尝试使用此代码来实现城堡windsor中的Factory,但它会抛出异常,如本期标题所示.我在这里关注文档的例子.请指出我出错的地方.

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>();

    }
}
Run Code Online (Sandbox Code Playgroud)

}

Krz*_*mic 8

是不是内在的例外解释得不够好?

AsFactoryImplementation.IDummyComponnentFactoryDynamicProxy看不到类型.无法为无法访问的类型创建代理.将类型设置为public或internal,并使用[assembly: InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)] attribute 标记程序集 .