Exception : ComponentActivator: could not proxy AsFactoryImplementation.<FactoryType>

↘锁芯ラ 提交于 2019-12-11 03:33:08

问题


I tried this code for implement the Factory in castle windsor, but it throws and exception as shown in title of this issue. i am following the examples of Documentation here. plz point out where i am getting wrong.

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

    }
}

}


回答1:


Isn't the inner exception explaining it well enough?

Type AsFactoryImplementation.IDummyComponnentFactory is not visible to DynamicProxy. Can not create proxy for types that are not accessible. Make the type public, or internal and mark your assembly with [assembly: InternalsVisibleTo(InternalsVisible.ToDynamicProxyGenAssembly2)] attribute.



来源:https://stackoverflow.com/questions/14750615/exception-componentactivator-could-not-proxy-asfactoryimplementation-factory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!