Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I have a Typed Factory in Castle Windsor registered like
container.Register(Component.For<IMyTypeFactory>().AsFactory());
and the interface registered like
container.Register(Component.For<IMyType>()
.ImplementedBy<MyType>().LifestyleTransient()
.Interceptors(typeof(MyInterceptor));
I have also registered the facility like
if (!container.Kernel.GetFacilities().Any(f => f is TypedFactoryFacility))
container.AddFacility<TypedFactoryFacility>(); // Due to the debugger this line is reached.
When I try to resolve an instance of IMyClass like
var myFactory = container.Resolve<IMyFactory>();
var myClass = myFactory.GetMyClass(myParameter); // This is where I get the exception
an exception is thrown with the message
Castle.MicroKernel.ComponentNotFoundException: 'Requested component named 'IMyClass' was not found in the container. Did you forget to register it?
There is one other component supporting requested service 'The.Name.Space.IMyClass'. Is it what you were looking for?'
My IMyTypeFactory looks like this:
public interface IMyTypeFactory
IMyType GetIMyType(IMyParameter myParameter);
MyType constructor looks like this:
public MyType(
IOneProperlyResolvedType oneProperlyResolvedType,
IAnotherProperlyResolvedType anotherProperlyResolvedType,
IMyParameter myParameter)
this.oneProperlyResolvedType = oneProperlyResolvedType;
this.anotherProperlyResolvedType = anotherProperlyResolvedType;
this.myParameter = myParameter;
I can see how that can be confusing. It has nothing to do with namespace.
Your factory method is called GetMyClass
and 'Get' methods lookup components by name so Windsor looks for a component named MyClass
, which happens to be the name of your class sans namespace.
To turn that off change the factory registration to
.AsFactory(new DefaultTypedFactoryComponentSelector(getMethodsResolveByName: false)));
Or rename the method.
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.