A package that provides registrations and resolves of services and other shite in the fast and lightweight container.
Download for WPF with Prism:
dotnet add package Abdrakov.Container.PrismAdapter
<PackageReference Include="Abdrakov.Container.PrismAdapter" Version="*" />
Download for Avalonia with Prism.Avalonia:
dotnet add package Abdrakov.Container.AvaloniaPrismAdapter
<PackageReference Include="Abdrakov.Container.AvaloniaPrismAdapter" Version="*" />
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 be used with Abdrakov.Container. 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:
private class FirstClass
{
[Injection]
SecondClass InjectedClass { get; set; }
}
private class SecondClass
{
[Injection]
FirstClass InjectedClass { get; set; }
}
And this would work as expected!
- Abdrakov.Container' logo - Material Design Icons
- Abdrakov.Container is a rewritten part of UnityContainer