Hey Krzystof, your last reply got caught in my spam filter for some
reason.
I just tried this syntax and unfortunately now I get the following
exception (even before "YourFactory" is called):
Castle.Core.Internal.LateBoundComponent is not a
GenericTypeDefinition. MakeGenericType may only be called on a type
for which Type.IsGenericTypeDefinition is true.
Full stack trace:
[InvalidOperationException: Castle.Core.Internal.LateBoundComponent is
not a GenericTypeDefinition. MakeGenericType may only be called on a
type for which Type.IsGenericTypeDefinition is true.]
System.RuntimeType.MakeGenericType(Type[] instantiation) +9484789
Castle.MicroKernel.Handlers.DefaultGenericHandler.ResolveCore(CreationContext
context, Boolean requiresDecommission, Boolean instanceRequired) in e:
\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel\Handlers
\DefaultGenericHandler.cs:52
Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext
context, Boolean instanceRequired) in e:\OSS.Code\Castle.Windsor\src
\Castle.Windsor\MicroKernel\Handlers\AbstractHandler.cs:771
Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext
context) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel
\Handlers\AbstractHandler.cs:369
Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveServiceDependency(CreationContext
context, ComponentModel model, DependencyModel dependency) in e:
\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel\Resolvers
\DefaultDependencyResolver.cs:390
Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext
context, ISubDependencyResolver contextHandlerResolver, ComponentModel
model, DependencyModel dependency) in e:\OSS.Code\Castle.Windsor\src
\Castle.Windsor\MicroKernel\Resolvers\DefaultDependencyResolver.cs:243
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArgumentsCore(ConstructorCandidate
constructor, Object[] arguments, CreationContext context, Type[]
signature) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel
\ComponentActivator\DefaultComponentActivator.cs:353
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate
constructor, CreationContext context, Type[]& signature) in e:\OSS.Code
\Castle.Windsor\src\Castle.Windsor\MicroKernel\ComponentActivator
\DefaultComponentActivator.cs:338
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext
context) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel
\ComponentActivator\DefaultComponentActivator.cs:90
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext
context) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel
\ComponentActivator\DefaultComponentActivator.cs:70
Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext
context) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel
\ComponentActivator\AbstractComponentActivator.cs:75
Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext
context) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel
\Lifestyle\AbstractLifestyleManager.cs:42
Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleManager.Resolve(CreationContext
context) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel
\Lifestyle\PerWebRequestLifestyleManager.cs:55
Nancy.BootStrappers.Windsor.HybridPerWebRequestLifestyleManager`1.Resolve(CreationContext
context) +125
Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext
context, Boolean requiresDecommission, Boolean instanceRequired) in e:
\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel\Handlers
\DefaultHandler.cs:61
Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext
context, Boolean instanceRequired) in e:\OSS.Code\Castle.Windsor\src
\Castle.Windsor\MicroKernel\Handlers\AbstractHandler.cs:771
Castle.MicroKernel.Handlers.AbstractHandler.TryResolve(CreationContext
context) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel
\Handlers\AbstractHandler.cs:376
Castle.MicroKernel.DefaultKernel.TryResolveComponent(IHandler
handler, Type service, IDictionary additionalArguments) in e:\OSS.Code
\Castle.Windsor\src\Castle.Windsor\MicroKernel\DefaultKernel.cs:915
Castle.MicroKernel.DefaultKernel.ResolveAll(Type service,
IDictionary arguments) in e:\OSS.Code\Castle.Windsor\src\Castle.Windsor
\MicroKernel\DefaultKernel_Resolve.cs:277
Castle.MicroKernel.DefaultKernel.ResolveAll(Type service) in e:
\OSS.Code\Castle.Windsor\src\Castle.Windsor\MicroKernel
\DefaultKernel_Resolve.cs:250
Castle.Windsor.WindsorContainer.ResolveAll(Type service) in e:
\OSS.Code\Castle.Windsor\src\Castle.Windsor\Windsor
\WindsorContainer.cs:896
Castle.Windsor.WindsorContainer.ResolveAll() in e:\OSS.Code
\Castle.Windsor\src\Castle.Windsor\Windsor\WindsorContainer.cs:891
Nancy.Bootstrappers.Windsor.WindsorNancyAspNetBootstrapper.GetAllModules(IWindsorContainer
container) +63
Nancy.Bootstrapper.NancyBootstrapperWithRequestContainerBase`1.GetAllModules(NancyContext
context) +78
Nancy.Routing.RouteCache..ctor(INancyModuleCatalog moduleCatalog,
IModuleKeyGenerator moduleKeyGenerator, INancyContextFactory
contextFactory) +112
On May 17, 1:07 am, Krzysztof Koźmic <[email protected]>
wrote:
.UsingFactoryMethod((k,m,c) => YourFactory(m.Implementation));
On 17/05/2012 5:35 PM, Nik Pinski wrote:
Could you be a little more clear? This really isn't much to go on,
and while I understand conceptually the kind of reflection the factory
method would have to do, I don't understand how to register the
generic MyGenericObject<T> where T is passed in to the factory method...
On Tue, May 15, 2012 at 2:59 AM, Krzysztof Koźmic
<[email protected] <mailto:[email protected]>> wrote:
yes
On 15/05/2012 8:54 AM, npinski wrote:
That's fine. But i'm not sure I understand...what kind of
signature
would the configuration have to have? I assume you are
implying the
type of the generic parameter would need to be passed in to the
factory method?
On May 11, 3:45 pm, Krzysztof
Koźmic<[email protected]
<mailto:[email protected]>>
wrote:
You can but since c# doesn't support that your factory
method would have
to do some reflection.
@K
On 12/05/2012 4:27 AM, npinski wrote:
Hi there,
Is there a way to register a WindsorContainer to
resolve a generic
type using a generic factory method?
I know I can do registration like:
Component.For<IMyService>().ImplementedBy<MyServiceImpl>()
and
Component.For<MyObject>().UsingFactoryMethod(MyObjectFactory.Create)
and even
Component.For(typeof(IMyGenericService<>)).ImplementedBy(typeof(MyGenericSe
rviceImpl<>))
what I'm looking for is something like:
Component.For(typeof(MyGenericObject<>)).UsingFactoryMethod(MyGenericObject
Factory.Create<>())
Is there a way to do this in a clean way? I started
peripherally
reading about IGenericImplementationMatchingStrategy,
and Typed
Factory Facilities, but this seems like overkill for
what I'm doing.
The workaround I have right now is to create a wrapper for
MyGenericObject<>, and have an interface for the
wrapper, which I can
then register with the aforementioned syntax
Component.For(typeof(IMyGenericService<>)).ImplementedBy(typeof(MyGenericSe
rviceImpl<>))
Thanks in advance, guys!
--
You received this message because you are subscribed to the Google
Groups "Castle Project Development List" group.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
To unsubscribe from this group, send email to
[email protected]
<mailto:castle-project-devel%[email protected]>.
For more options, visit this group at
http://groups.google.com/group/castle-project-devel?hl=en.
--
Nik.
--
You received this message because you are subscribed to the Google
Groups "Castle Project Development List" group.
To post to this group, send email to
[email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-devel?hl=en.