DEV Community

Discussion on: .NET Core Dependency Injection: Everything You Ought To Know

Collapse
 
timothymcgrath profile image
Timothy McGrath

That strategy pattern code is interesting. I had no idea you could do this:

services.AddScoped<IMathOperator, AddOperator>();
services.AddScoped<IMathOperator, SubtractOperator>();
services.AddScoped<IMathOperator, MultipleOperator>();
services.AddScoped<IMathOperator, DivideOperator>();
Thread Thread
 
jamesmh profile image
James Hickey

It's pretty neat! As long as your interface exposes some way to differentiate between each concrete implementation then you can just check that at run-time.