Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

CrackAndDie/Abdrakov.Container

Repository files navigation

Abdrakov.Solutions logo

Abdrakov.Container

Prism Adapter:

Nuget Nuget License

Prism.Avalonia Adapter:

Nuget Nuget License

About:

A package that provides registrations and resolves of services and other shite in the fast and lightweight container.

Download for WPF with Prism:

.NET CLI:

dotnet add package Abdrakov.Container.PrismAdapter

Package Reference:

<PackageReference Include="Abdrakov.Container.PrismAdapter" Version="*" />

Download for Avalonia with Prism.Avalonia:

.NET CLI:

dotnet add package Abdrakov.Container.AvaloniaPrismAdapter

Package Reference:

<PackageReference Include="Abdrakov.Container.AvaloniaPrismAdapter" Version="*" />

Features:

Attribute injections:

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;
}

Constructor injections:

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").

Inheritance injections:

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.

Recursive injections:

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!

Powered by:

About

A package that provides registrations and resolves of services and other shite in the fast and lightweight container.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages