dependency injection and optional params on assembly scanning

kaszojad

New member
Joined
Sep 4, 2020
Messages
1
Programming Experience
5-10
With autofac I'm to add a parameter to the constructor and even more, the parameter can be optional
C#:
//autofac 
Builder
.RegisterAssemblyTypes(assemblies)
.Where(t => typeof(T).IsAssignableFrom(t))
.SingleInstance()
.AsSelf()
.WithParameter(new ResolvedParameter(
(pi, ctx) => pi.ParameterType == typeof(IMyService),
(pi, ctx) => ctx.ResolveOptional<IMyService>() ));

Could you help do this with the default MS dependency container and Scrutor?
C#:
/MS Dependency Container

Builder
.Scan(s =>               
s.FromAssemblies(assemblies)
.AddClasses(c => c.AssignableTo(typeof(T)))
.AsSelf()
.WithTransientLifetime() );

Thank you in advance for help and answer
 
What is Scrutor?

From persona experience, asking Autofac questions on StackOverflow often gets very fast responses from the author(s) of Autofac and various folks who write the blogs talking about how to maximize the features offered by Autofac.
 
Back
Top Bottom