Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
CrackAndDie committed Feb 28, 2024
1 parent 4a2ff27 commit 1875aea
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,106 @@

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.

<h2>LightContainer</h2>

<h3>Why should I use LightContainer?</h3>

*Hypocrite.Services* provides You light and fast DI container called *LightContainer*. Here are some features of it:

<h4>Attribute injections:</h4>

All the registered shite could be resolved via *Injection* attribute (use the attribute only for properties and fields) like this:
```c#
private class NormalClass
{
[Injection]
InjectedClass TestClass { get; set; }
[Injection]
AnotherInjectedClass _anotherTestClass;
}
```

<h4>Constructor injections:</h4>

Parametrised constructors could also be used (this feature is not fully provided by *UnityContainer*). For example after registering and resolving the class:
```c#
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").

<h4>Inheritance injections:</h4>

The classed from which Your class is inherited would also be prepared for injections:
```c#
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.

<h4>Recursive injections:</h4>

There could be two classes that require injection of each other (this feature is not provided by *UnityContainer*):
```c#
private class FirstClass
{
[Injection]
SecondClass InjectedClass { get; set; }
}

private class SecondClass
{
[Injection]
FirstClass InjectedClass { get; set; }
}
```
And this would work as expected!

<h3>What about speed?</h3>

After some benchmarks on my shity laptop (idk and idc about its parameters) I got the following things:

![image](https://github.com/CrackAndDie/Hypocrite.Services/assets/52558686/9f6636f6-7a1d-464f-b795-29129cba3a7d)

Singleton resolve:
![image](https://github.com/CrackAndDie/Hypocrite.Services/assets/52558686/8e9e2df9-2632-4512-b5da-5a6f006e8861)
Type resolve:
![image](https://github.com/CrackAndDie/Hypocrite.Services/assets/52558686/655b8ca1-2734-42c4-9d9f-eaff5e1d7d1a)

But... there is a moment with injections cause they're quite powerful in *LightContainer*:

![image](https://github.com/CrackAndDie/Hypocrite.Services/assets/52558686/2ae3642f-889b-4131-9943-6b54e90a3b08)

Type resolve with constructor injections:
![image](https://github.com/CrackAndDie/Hypocrite.Services/assets/52558686/694c1808-ee27-4074-9a15-116335312210)
Type resolve with fields and properties injections:
![image](https://github.com/CrackAndDie/Hypocrite.Services/assets/52558686/8a0c8798-f1d5-4b4e-814e-1ffc93c92252)



<h2>Read more:</h2>

Read more about how to use the library with [WPF](https://github.com/CrackAndDie/Hypocrite.Services/blob/main/README_Wpf.md) or [Avalonia](https://github.com/CrackAndDie/Hypocrite.Services/blob/main/README_Avalonia.md).

0 comments on commit 1875aea

Please sign in to comment.