How to Resolve a Setting:ISetting in DependencyRegistrar

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 anni tempo fa
Hi.
Is there any way to resolve  another service or Setting while registering a dependency in your plugin DependencyRegistrar ?
I want to setup a typed client for one of my services and need to read the auth2 parameters from settings which is saved in Db before.
I tried the followings :
var settings = EngineContext.Current.Resolve<ApiSettings>();

which returns null
and
var ApiSettings = services.BuildServiceProvider().GetRequiredService<ApiSettings>();

which leads to a null reference exception.
Any Idea ?
2 anni tempo fa
why aren't you using  ISettingService ?

private readonly ISettingService _settingService;

public Constructor( ISettingService settingService){
_settingService  =  settingService;
}

Method() {
//load settings for a chosen store scope
            var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync();
            var productSyncSettings = await _settingService.LoadSettingAsync<ProductSyncSettings>(storeScope);
}
2 anni tempo fa
How it could be possible in Register method of the DependencyRegistrar in a plugin?
Did you read the title of topic carefully?


public class DependencyRegistrar : IDependencyRegistrar
    {
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="appSettings">App settings</param>
        public void Register(IServiceCollection services, ITypeFinder typeFinder, AppSettings appSettings)
        {
            //HERE!
        }

        public int Order =>11;
    }
2 anni tempo fa
rahiqi wrote:
How it could be possible in Register method of the DependencyRegistrar in a plugin?


Seems you've already done most of it. Here is an example.


public class DependencyRegistrar : IDependencyRegistrar
    {
        public int Order => 1;

        public void Register(IServiceCollection services, ITypeFinder typeFinder, AppSettings appSettings)
        {
            services.AddScoped<IdummyService1, dummyService1>();
            services.AddTransient<IdummyService2, dummyService2>();
            services.AddSingleton<IdummyService3, dummyService3>();
        }
    }
2 anni tempo fa
It seems I'm conveying my purpose badly.

I NEED to use another service to register my service and that service is Setting or ISettingService itself
    

       var ApiSettings = services.BuildServiceProvider().GetRequiredService<ApiSettings>();
            EngineContext.Current.Resolve<ApiSettings>();
            services.AddAccessTokenManagement(options =>
            {
                options.Client.Clients.Add("someApi", new ClientCredentialsTokenRequest
                {
                    Address = someApiSettings.TokenEndpoint,
                    ClientId =  someApiSettings.ClientId,
                    ClientSecret = someApiSettings.ClientSecret,
                    Scope = "api" // optional
                });
            });


I need ApiSettings  to be resolved but it's null
2 anni tempo fa
See if this helps
https://www.nopcommerce.com/en/boards/topic/55525/how-do-i-get-access-to-the-isettingservice-in-my-plugins-dependencyregistrar-class#212539
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.