4 ms·
I skimmed the post. Looks like asp.net approach of registering all dependencies up front (with various lifetimes/scopes). Still looks very verbose. But then as
by dmitriid 4y ago
I skimmed the post. Looks like asp.net approach of registering all dependencies up front (with various lifetimes/scopes).
Still looks very verbose. But then asp.net has had a decade, and this project is new.
- smt88 4y agoI loathe this approach. Declarative architecture is incredibly hard to debug and understand.
- dmitriid 4y agoThere's nothing declarative in asp.net. You specifically define services and dependencies in one place in code. It goes something like this: public void ConfigureServices(IServiceCollection services) { // Add framework services. // Add application services. services.AddTransient<Type, ClassThatImplementsType>(); services.AddScoped<Type, ClassThatImplementsType>(); // etc. } So when dependency injection happens, you know exactly which class is used, and where it was added.
- smt88 4y agoThat's declarative. You're injecting code using the type system. You aren't directly calling any constructors with those classes -- they're added in code that you can't easily put a breakpoint in. The result is that you're looking at a class with a dependency of "ISomething" and you can't click through to the class. You have to go back and find where the services were configured (which sometimes isn't intuitive, depending on how the original person wrote the code). The worst is when there are entire behaviors added this way, and you just have to search your code base for keywords to figure out what's happening. It's awful. .NET is a great ecosystem, but the ".NET way" of doing the architecture is insane and not ergonomic.
- dmitriid 4y ago> The result is that you're looking at a class with a dependency of "ISomething" and you can't click through to the class. You can. Jetbrains' Rider will happily show you the implementation (Cmd + Option + Click IIRC) > The worst is when there are entire behaviors added this way, and you just have to search your code base for keywords to figure out what's happening. Not in ASP.net in mu experience. But true for Spring in Java. In ASP only the classes you declare in the constructor get injected. Only the classes registered in ConfigureServices get injected etc. All in all ASP.net has surprisingly little magic compared to many other frameworks. That's not to say it's without warts. There are definitely WTF cases and places where you can't properly stop a debugger.