2 ms·
> Years ago, in .NET and Java, it was popular to use an Inversion of Control container with XML configuration that declared and configured different classes and
by SideburnsOfDoom 3y ago
> Years ago, in .NET and Java, it was popular to use an Inversion of Control container with XML configuration that declared and configured different classes and objects. I think it largely went out of style because it’s complicated, or at least more complicated than it needed to be.
In .NET anyway, this was replaced by use an Inversion of Control container with configuration as code. Because it's more flexible if you need that. And if you don't, it's just a boring (in the good sense) list of e.g.:
services.AddTransient<IFoo, FooService>();
services.AddScoped<IBar, BarService>();
services.AddSingleton<SomeType>();
// etc for many lines
This is definitely no worse than XML.
It's now as simple or as complicated as you want it to be. Using the same tools as the rest of the app code rather than a different syntax.
- brodo 3y agoI also don't think it's out of style if you have a .Net monolith. It's already there; there's no need to include or install anything. So people use it. It's a little too much magic for my taste, but people like magic.
- SideburnsOfDoom 3y agoIn my experience in .NET recently, Inversion of Control containers are as popular as ever; typically just using the one that's "already there". But it's the "config as a XML file" that is right out of style, in favour of config as code, for the reasons given.
- daxfohl 3y agoHaving moved from .net to java recently, I have to say I miss the .net IoC ecosystem; things are simple and to the point, and you use the tools however best fits your use cases. In Java-land everything is Guice, which is more of a "framework"; it requires a lot more boilerplate and you have to design around it, and gets in your way any time you want to do anything outside of its golden path.