A package that helps You to create a powerful, flexible and loosely coupled WPF and Avalonia application. It fully supports Prism features and MVVM pattern.
Hypocrite.Services provides You light and fast DI container called LightContainer. Here are some features of it:
All the registered shite could be resolved via Injection attribute (use the attribute only for properties and fields) like this:
private class NormalClass
{
[Injection]
InjectedClass TestClass { get; set; }
[Injection]
AnotherInjectedClass _anotherTestClass;
}
Parametrised constructors could also be used (this feature is not fully provided by UnityContainer). For example after registering and resolving the class:
private class NormalClass
{
private InjectedClass _testClass;
private int _a;
private string _b;
public NormalClass(InjectedClass testClass, int a, string b = "awd")
{
_testClass = testClass;
_a = a;
_b = b;
}
}
the testClass parameter would be resolved as usual (if it is not registered in the container then an instance of it would be created); the a parameter would have default type value (for Int32 is 0); the b parameter would have its default parameter value (in this case is "awd").
The classed from which Your class is inherited would also be prepared for injections:
private class InjectedClass
{
internal int A { get; set; }
}
private class BaseClass
{
[Injection]
protected InjectedClass TestClass { get; set; }
}
private class NormalClass : BaseClass
{
}
So in this case after NormalClass registration and resolve, the TestClass property would also be injected.
There could be two classes that require injection of each other (this feature is not provided by UnityContainer):
private class FirstClass
{
[Injection]
SecondClass InjectedClass { get; set; }
}
private class SecondClass
{
[Injection]
FirstClass InjectedClass { get; set; }
}
And this would work as expected!
After some benchmarks on my shity laptop (idk and idc about its parameters) I got the following things:
Singleton resolve:
Type resolve:
But... there is a moment with injections cause they're quite powerful in LightContainer:
Type resolve with constructor injections:
Type resolve with fields and properties injections:
Read more about how to use the library with WPF or Avalonia.