Open Closed

New Project with new console template cannot utilize service with ISettingProvider, receive dependency resolution exception #1106


User avatar
0
developers@ten3.systems created
  • ABP Framework version: v4.2.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
Autofac.Core.DependencyResolutionException
 HResult=0x80131500
 Message=An exception was thrown while activating Volo.Abp.Settings.DefaultValueSettingValueProvider -> Volo.Abp.SettingManagement.SettingStore -> Volo.Abp.SettingManagement.SettingManagementStore.
 Source=Autofac
 StackTrace:
  at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
  at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt)
  at Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext ctxt)
  at Autofac.Core.Resolving.Middleware.RegistrationPipelineInvokeMiddleware.Execute(ResolveRequestContext context, Action`1 next)
  at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt)
  at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
  at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.&lt;&gt;c__DisplayClass14_0.&lt;BuildPipeline&gt;b__1(ResolveRequestContext ctxt)
  at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.&lt;&gt;c__DisplayClass14_0.&lt;BuildPipeline&gt;b__1(ResolveRequestContext ctxt)
  at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)
  at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt)
  at Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext ctxt)
  at Autofac.Core.Resolving.ResolveOperation.InvokePipeline(ResolveRequest request, DefaultResolveRequestContext requestContext)
  at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)
  at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)
  at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest request)
  at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request)
  at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
  at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
  at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable`1 parameters)
  at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType)
  at Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetRequiredService(Type serviceType)
  at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
  at Volo.Abp.Settings.SettingValueProviderManager.&lt;&gt;c__DisplayClass6_0.&lt;.ctor&gt;b__1(Type type)
  at System.Linq.Enumerable.SelectIListIterator`2.ToList()
  at Volo.Abp.Settings.SettingValueProviderManager.<>c__DisplayClass6_0.<.ctor>b__0()
  at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
  at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
  at System.Lazy`1.CreateValue()
  at System.Lazy`1.get_Value()
  at Volo.Abp.Settings.SettingValueProviderManager.get_Providers()
  at Volo.Abp.Settings.SettingProvider.<GetOrNullAsync>d__10.MoveNext()
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
  at TestAbpApp.HelloWorldService.&lt;SayHello&gt;d__2.MoveNext() in D:\Programming\_play\TestAbpApp\aspnet-core\src\TestAbpApp.Application\HelloWorldService.cs:line 19

 This exception was originally thrown at this call stack:
   [External Code]

Inner Exception 1:
DependencyResolutionException: None of the constructors found with 'Volo.Abp.Autofac.AbpAutofacConstructorFinder' on type 'Volo.Abp.SettingManagement.SettingManagementStore' can be invoked with the available services and parameters:
Cannot resolve parameter 'Volo.Abp.SettingManagement.ISettingRepository settingRepository' of constructor 'Void .ctor(Volo.Abp.SettingManagement.ISettingRepository, Volo.Abp.Guids.IGuidGenerator, Volo.Abp.Caching.IDistributedCache 1[Volo.Abp.SettingManagement.SettingCacheItem], Volo.Abp.Settings.ISettingDefinitionManager)'.
  • Steps to reproduce the issue:
  • Create new project via app template using above settings
  • use abp new -t console to create a new console project in the sln
  • take the HelloWorldService from the new console proj and move it to the MyApp.Application project
  • reference the ApplicationModule in the new console project using [DependsOn]
  • inject ISettingProvider into HelloWorldService
  • add setting to the domain module's settingDefinitionProvider
  • add setting to appsettings.json
  • try to use the SettingProvider to GetOrNullAsync
  • cry

/src/MyApp.Domain/Settings/MyAppSettingDefinitionProvider.cs

    public class TestAbpAppSettingDefinitionProvider : SettingDefinitionProvider
    {
        public override void Define(ISettingDefinitionContext context)
        {
            //Define your own settings here. Example:
            context.Add(new SettingDefinition("Test"));
        }
    }
    ```
/src/MyApp.Application/HelloWorldService.cs
public class HelloWorldService : ITransientDependency
{
    private readonly ISettingProvider _settingProvider;

    public HelloWorldService(ISettingProvider settingProvider)
    {
        _settingProvider = settingProvider;
    }

    public async void SayHello()
    {
        Console.WriteLine("Hello World!");
        var setting = await _settingProvider.GetOrNullAsync("Test");
        Console.WriteLine(setting);
    }
}
```

2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share the problem project with me? liming.ma@volosoft.com

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 26, 2024, 06:07