问题
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