Skip to content

Instantly share code, notes, and snippets.

@madstt
Created November 14, 2012 08:56
Show Gist options
  • Save madstt/4071068 to your computer and use it in GitHub Desktop.
Save madstt/4071068 to your computer and use it in GitHub Desktop.
Castle Windsor generics
CastleHelper.IocContainer.Register(
Component.For(typeof(IRepository<>)).ImplementedBy(typeof(NHibernateRepository<>)).Named("NHibernateRepository").LifeStyle.Is(LifestyleType.Transient));
var repo = (IRepository<T>)CastleHelper.IocContainer.Resolve(typeof(IRepository<T>));
// Gives me this exception:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Castle.MicroKernel.Releasers.LifecycledComponentsReleasePolicy.Track(Object instance, Burden burden)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Track(Burden burden, IReleasePolicy releasePolicy)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernel(CreationContext context, ComponentModel model, DependencyModel dependency)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveCore(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context)
at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally)
at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
at Castle.MicroKernel.Handlers.DefaultGenericHandler.Resolve(CreationContext context, Boolean instanceRequired)
at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy)
at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
at Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments)
at Castle.Windsor.WindsorContainer.Resolve(Type service)
at DongEnergy.Upstream.EagleIntegration.Utilities.RepositoryHelper.GetRepository[T]() in c:\Projects\Eagle\devel\main\Integration\EagleIntegrationPoint.Utilities\RepositoryHelper.cs:line 21
at DongEnergy.Upstream.EagleIntegration.BusinessLogic.SystemInfoController..ctor() in c:\Projects\Eagle\devel\main\Integration\EagleIntegrationPoint.BusinessLogic\SystemInfoController.cs:line 22
at DongEnergy.Upstream.EagleIntegration.Services.ServiceBase..ctor() in c:\Projects\Eagle\devel\main\Integration\EagleIntegrationPoint.Services\ServiceBase.cs:line 95
at DongEnergy.Upstream.EagleIntegration.Services.EagleIntegrationMappingService..ctor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment