gpt4 book ai didi

c# - CaSTLe.Windsor 3.1 - 组件激活器 : could not proxy

转载 作者:行者123 更新时间:2023-12-03 21:51:48 26 4
gpt4 key购买 nike

我正在从 2.5.1 版升级到 3.1.0 版,以前的功能不再有效。我正在尝试解决创建使用泛型的组件的工厂。抛出的错误是“ComponentActivator: could not proxy” 其中是无法解析的工厂名称

public class MyObject { }

public class MyContext { }

public class DummyComponent<T> : IDummyComponent<T> where T : MyObject { }

public interface IDummyComponent<T> { }

public interface IDummyComponentFactory
{
IDummyComponent<T> Create<T>(object o);
}

class Program
{
static void Main(string[] args)
{
var windsorContainer = new WindsorContainer();
windsorContainer.AddFacility<TypedFactoryFacility>()
.Register(
Component.For(typeof(IDummyComponent<>)).ImplementedBy(typeof(DummyComponent<>)),
Component.For<IDummyComponentFactory>().AsFactory());
var factory = windsorContainer.Resolve<IDummyComponentFactory>(); <-- Error Occurs Here
var myDummyComponent = factory.Create<MyObject>(new object());
}
}

此代码在 Entity Framework 存储库中以下列方式使用,用于将 EntityContext 传递到另一个存储库,以便像这样处理已删除的对象:

    public virtual IEnumerable<T> Where(Expression<Func<T, bool>> predicate, bool showDeleted = false, MergeOption mergeOption = MergeOption.AppendOnly)
{
if (typeof(IDeletable).IsAssignableFrom(typeof(T)))
{
var factory = Container.Instance.Resolve<IDeletableRepositoryFactory>();
var repository = factory.GetDeletableRepository<T>(EntityContext);
return repository.Where(predicate, showDeleted, mergeOption);
}

return GetObjectSet(mergeOption).Where(predicate);
}

更新:包括内部异常

System.Security.VerificationException
{"Operation could destabilize the runtime."} at
Castle.MicroKernel.Proxy.ProxyOptions.get_MixIns() in
c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\Proxy\ProxyOptions.cs:line 96 at
Castle.Windsor.Proxy.DefaultProxyFactory.CreateProxyGenerationOptionsFrom(ProxyOptions proxyOptions, IKernel kernel, CreationContext context, ComponentModel model) in
c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\Proxy\DefaultProxyFactory.cs:line 178 at
Castle.Windsor.Proxy.DefaultProxyFactory.Create(IKernel kernel, Object target, ComponentModel model, CreationContext context, Object[] constructorArguments) in
c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\Proxy\DefaultProxyFactory.cs:line 105 at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) in
c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\ComponentActivator\DefaultComponentActivator.cs:line 123`

最佳答案

我试过运行你的代码,但它在我的机器上运行

enter image description here

关于c# - CaSTLe.Windsor 3.1 - 组件激活器 : could not proxy <FactoryName>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12627467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com