.NetCore dependency injection and optional params on assembly scanning

Sep 4 2020 1:10 PM
With autofac I'm to add a parameter to the constructor and even more, the parameter can be optional
  1. //autofac  
  2. Builder  
  3. .RegisterAssemblyTypes(assemblies)  
  4. .Where(t => typeof(T).IsAssignableFrom(t))  
  5. .SingleInstance()  
  6. .AsSelf()  
  7. .WithParameter(new ResolvedParameter(  
  8. (pi, ctx) => pi.ParameterType == typeof(IMyService),  
  9. (pi, ctx) => ctx.ResolveOptional<IMyService>() ));  
Could you help do this with the default MS dependency container and Scrutor?
 
What should I add here:
  1. //MS Dependency Container  
  2. Builder  
  3. .Scan(s =>  
  4. s.FromAssemblies(assemblies)  
  5. .AddClasses(c => c.AssignableTo(typeof(T)))  
  6. .AsSelf()  
  7. .WithTransientLifetime() );  
Thank you in advance for help and answer

Answers (1)