Reputation: 12526
We have a large solution with 24 projects which uses autofac (v3.5.2) and largely constructor DI to construct all our services.
The solution is so large now that it seems I've reached a limit. I recently added a few more constructor DIs to an existing service and when I load and run the project I now get an OutOfMemoryException. If I remove those new DIs in that service, the project loads again.
There is no circular dependency or anything like that causing it.
So the question is, does Autofac have this type of limit? If not, what could be causing this OutOfMemoryException?
Here's the top part of the stack trace:
[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]
Autofac.Core.Activators.Reflection.AutowiringParameter.CanSupplyValue(ParameterInfo pi, IComponentContext context, Func`1& valueProvider) +246
Autofac.Core.Activators.Reflection.ConstructorParameterBinding..ctor(ConstructorInfo ci, IEnumerable`1 availableParameters, IComponentContext context) +435
Autofac.Core.Activators.Reflection.<>c__DisplayClass13_0.<GetConstructorBindings>b__0(ConstructorInfo ci) +67
System.Linq.WhereSelectArrayIterator`2.MoveNext() +58
System.Linq.WhereEnumerableIterator`1.MoveNext() +174
System.Linq.Buffer`1..ctor(IEnumerable`1 source) +135
System.Linq.Enumerable.ToArray(IEnumerable`1 source) +79
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +518
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +124
[DependencyResolutionException:
An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserRetriever (ReflectionActivator),
Services = [MyCoolApp.Domain.IUserRetriever],
Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None,
Ownership = OwnedByLifetimeScope ---> Exception of type 'System.OutOfMemoryException' was thrown. (See inner exception for details.)]
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +274
Autofac.Core.Resolving.InstanceLookup.Execute() +341
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +281
Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +72
Autofac.Core.Registration.<>c__DisplayClass2_0.<RegistrationsFor>b__2(IComponentContext c, IEnumerable`1 p) +57
Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +188
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +124
[DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserRetriever (DelegateActivator), Services = [MyCoolApp.Domain.IUserRetriever], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserRetriever (ReflectionActivator), Services = [MyCoolApp.Domain.IUserRetriever], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> Exception of type 'System.OutOfMemoryException' was thrown. (See inner exception for details.) (See inner exception for details.)]
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +274
Autofac.Core.Resolving.InstanceLookup.Execute() +341
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +281
Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +72
Autofac.Core.Activators.Reflection.<>c__DisplayClass0_0.<CanSupplyValue>b__0() +82
Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +328
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +622
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +124
[DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserService (ReflectionActivator), Services = [MyCoolApp.Domain.Users.IUserService], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserRetriever (DelegateActivator), Services = [MyCoolApp.Domain.IUserRetriever], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserRetriever (ReflectionActivator), Services = [MyCoolApp.Domain.IUserRetriever], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> Exception of type 'System.OutOfMemoryException' was thrown. (See inner exception for details.) (See inner exception for details.) (See inner exception for details.)]
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +274
Autofac.Core.Resolving.InstanceLookup.Execute() +341
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +281
Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +72
Autofac.Core.Registration.<>c__DisplayClass2_0.<RegistrationsFor>b__2(IComponentContext c, IEnumerable`1 p) +57
Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +188
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +124
[DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserService (DelegateActivator), Services = [MyCoolApp.Domain.Users.IUserService], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserService (ReflectionActivator), Services = [MyCoolApp.Domain.Users.IUserService], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserRetriever (DelegateActivator), Services = [MyCoolApp.Domain.IUserRetriever], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = UserRetriever (ReflectionActivator), Services = [MyCoolApp.Domain.IUserRetriever], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> Exception of type 'System.OutOfMemoryException' was thrown. (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.)]
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +274
Autofac.Core.Resolving.InstanceLookup.Execute() +341
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +281
Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +72
Autofac.Core.Activators.Reflection.<>c__DisplayClass0_0.<CanSupplyValue>b__0() +82
Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +328
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +622
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +124
...
The full stack trace is too big to post on Stack Overflow, but you can the full stack trace here.
We do have some deep chains of dependency, but not circular. Every time we load the app the error follows a different dependency chain in the error messages. Here's one chain as an example:
RelatedEntityResolver -> IPermissionService
RoleResolver -> IRelatedEntityResolver
-> IPermissionService
UserRetriever -> IRelatedEntityResolver
-> IRoleResolver
-> IPermissionService
UserService -> IUserRetriever
RoleService -> IPermissionService
-> IRoleResolver
-> IRelatedEntityResolver
-> IUserRetriever
-> IUserService
TeamFactory -> IPermissionService
-> IRoleService
TeamInstanceForCompetitionCreator -> ITeamFactory
CommandDispatcher -> ICommandHandler/ITeamInstanceForCompetitionCreator
CreateAgreement -> ICommandDispatcher
Upvotes: -1
Views: 71