Question

This request might sounds a little bit odd, but application-performance and maintenance is cruciual, so I'm really looking for something as described.

Because I'm not sure if the 3 words are enough to explain what I'm looking for, here's an example:

I use IoC a lot, especially if I have dyniamical behaviours, which is often the case. It's a very easy and frankly cool technique to have a loose coupled application.

But the freedom comes with a price of a higher performance-cost, compared with a "hard wired" solution. Normally this is not a too big issue, but in the current case, it is.

So what I'd like to have is a feature which works like an IoC, but of course with a hard-wired .cs-file, instead of an "generated at runtime" Container. Like if I need all implementations of IBehaviour, I'd get an output such as "behaviours = new List { impl1, impl2, ... }, instead of behaviours = Container.GetAllInstancesOf()

Hope it's clear what I'm looking for and that something like this exists. And if not: What would be the way to implement this feature? Only way I can imagine is a VisualStudio-Plugin which reflects a compiled dll and with the help of custom attributes can write a .t4-file.

Cheers!

No correct solution

OTHER TIPS

I don't know if what you're looking for exists, but I implemented something which may serve as an example to get you started: a T4 typed factory generator. Basically you mark your class with an attribute and T4 will generate a factory implementation based on a factory interface (if it doesn't exist, the script will generate the factory interface as well).

You can look at the code at https://github.com/PombeirP/T4Factories, and a NuGet package is available at https://www.nuget.org/packages/T4Factories/.

Hope this helps.

Are you sure that ioc has:

higher performance-cost, compared with a "hard wired" solution

?

Comparing the performance, you can see that:

  • singleton registration takes 68ms, without container 78ms
  • transient (a new instance is created every time) takes 66ms, without container 88ms

Moreover, now IoC container is very small, for example DryIoc has no more than 2500 lines of code including comments.

Update:

DryIocZero supports compile-time generation of factories with all registered dependencies (I am a maintainer).

I'm currently working on a compile time IOC container for .Net which should have almost zero overhead (for many cases it generates practically the same code as you would write yourself). Try it out at https://github.com/YairHalberstadt/stronginject.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top