.NET
C#
Functional Programming
Comments 2
0
Hi Dmitry, great article and interesting approach!

You give an example of how to get a Reader<Service>:

public static Reader<TService> GetService<TService>() =>
Reader<TService>.Read<IServiceProvider>(serviceProvider
=> (TService)serviceProvider
.GetService(typeof(TService)));


It looks like the Service Locator pattern, that is considered an anti-pattern as it hides actual dependencies used by the code.
0
“Service Locator” is a part of almost any dependency injection library that I know. In most cases it is used implicitly and that mitigates the “anti” part of the pattern, but it has a side effect – all injected dependencies will be always resolved regardless of whether they are needed or not and sometimes that resolving might be resource consuming especially in the case when some dependency has the “per request” lifecycle.
Personally, I think that the “Service Locator” is just as anti-pattern as the “dependency injection” itself.
Only those users with full accounts are able to leave comments. , please.