dimanche 21 juin 2020

Some services are not able to be constructed when dynamic assembly loading

I am trying to add assembly by reflection in my .net core project (DNAPI). That external project (EBiletManager) include ILogger and other required services from other common reference project (DNDomain.proj).

public class EBiletManager : DNDomain.IScopedProcessingService {

    ILogger _logger;
    IConfiguration _configuration;

    public EBiletManager(ILogger logger, IConfiguration configuration,

...

When I add the EBiletManager to DNAPI from Project Dependencies, these are working correctly.

I spend hours for this problem and I try this plug-in methods. And I try copy all DLL references to \bin\Debug\netcoreapp3.1 folder but not working.

Assembly loading correctly but "EBiletManager" constractor throw this error.

System.AggregateException

Service description lines:

public static IServiceCollection AddCustomServices(this IServiceCollection services, IConfiguration configuration) {
            services.AddHostedService<TimedHostedService>();

            var loadContext = new PluginLoadContext(pluginLocation);
            var assembly = loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(pluginLocation)));
            foreach (Type type in assembly.GetTypes()) {
                if (type.GetInterface(nameof(DNDomain.IScopedProcessingService)) != null) {
                    services.AddScoped(typeof(DNDomain.IScopedProcessingService), type);
                }
            }
...

Sorry for bad English and thanks for helps.





Aucun commentaire:

Enregistrer un commentaire