I have three components: A, B and C.
They are recorded in the following manners:
public class Installer : IWindsorInstaller { public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register(Component.For<IA>().ImplementedBy<A>()); container.Register(Component.For<IB>().UsingFactoryMethod(Resolve).LifestyleScoped()); container.Register(Component.For<IC>().ImplementedBy<C>().LifestyleScoped()); } private static IUnitOfWork Resolve(IKernel kernel) { IA a = kernel.Resolve<IA>(); B b = new B(a); kernel.ReleaseComponent(a); return b; } }
When I enable C, I do it like this:
public void Test() { using (ContainerAccessor.Instance.IocContainer.BeginScope()) { using (IB b = containerAccessor.Instance.IocContainer.Resolve<IB>()) { IC c = ContainerAccessor.Instance.IocContainer.Resolve<IC>(); ... b.Commit(); return result; } }
the first time I access it, an exception is thrown: "InvalidOperationException: scope not available. Did you forget to call container.BeginScope ()?".
I partially solved it by wrapping the contents of the Resolve method with using (kernel.BeginScope) { ... } . I said this was partially resolved, because when I put a breakpoint in the resolution method, it still throws an exception the first time it is accessed. Does anyone have an idea of ββwhat's going on here?
Thank you very much.
source share