Skip to content

Commit 5ccb097

Browse files
Improve README.
1 parent 59b5cbd commit 5ccb097

File tree

3 files changed

+48
-21
lines changed

3 files changed

+48
-21
lines changed

LazyProxy.Unity.Sample/Program.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ private static void UnityExtensionExample1()
1919
var container = new UnityContainer()
2020
.RegisterLazy<IMyService, MyService>();
2121

22-
Console.WriteLine("Resolving service...");
22+
Console.WriteLine("Resolving the service...");
2323
var service = container.Resolve<IMyService>();
2424

25-
Console.WriteLine("Foo execution...");
25+
Console.WriteLine("Executing the 'Foo' method...");
2626
service.Foo();
2727
}
2828

@@ -56,4 +56,4 @@ private static void UnityExtensionExample2()
5656
}
5757
}
5858
}
59-
}
59+
}

LazyProxy.Unity.Sample/Services.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public interface IMyService
1010

1111
public class MyService : IMyService
1212
{
13-
public MyService() => Console.WriteLine("Hello from ctor");
14-
public void Foo() => Console.WriteLine("Hello from Foo");
13+
public MyService() => Console.WriteLine("Ctor");
14+
public void Foo() => Console.WriteLine("Foo");
1515
}
1616

1717
public abstract class Warrior
@@ -111,4 +111,4 @@ public Weapon CreateShuriken()
111111
return new Weapon(damage);
112112
}
113113
}
114-
}
114+
}

README.md

+42-15
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,63 @@
1-
# Lazy injection for Unity container
1+
# Lazy Dependency Injection for Unity Container
22

3-
A [LazyProxy](https://github.com/servicetitan/lazy-proxy) can be used for IoC containers to change the resolving behaviour.
3+
A [LazyProxy](https://github.com/servicetitan/lazy-proxy) can be used for IoC containers to improve performance by changing the resolve behavior.
44

5-
Dependencies registered as lazy are created as dynamic proxy objects built in real time, but the real classes are resolved only after the first execution of proxy method or property.
5+
More info can be found in the article about [Lazy Dependency Injection for .NET](https://dev.to/hypercodeplace/lazy-dependency-injection-37en).
66

7-
Also dynamic lazy proxy allows injection of circular dependencies.
7+
## Get Packages
88

9-
```C#
9+
The library provides in NuGet.
10+
11+
```
12+
Install-Package LazyProxy.Unity
13+
```
14+
15+
## Get Started
16+
17+
Consider the following service:
18+
19+
```CSharp
20+
public interface IMyService
21+
{
22+
void Foo();
23+
}
24+
25+
public class MyService : IMyService
26+
{
27+
public MyService() => Console.WriteLine("Ctor");
28+
public void Foo() => Console.WriteLine("Foo");
29+
}
30+
```
31+
32+
A lazy registration for this service can be added like this:
33+
34+
```CSharp
1035
var container = new UnityContainer().RegisterLazy<IMyService, MyService>();
1136

12-
Console.WriteLine("Resolving service...");
37+
Console.WriteLine("Resolving the service...");
1338
var service = container.Resolve<IMyService>();
1439

15-
Console.WriteLine("Foo execution...");
40+
Console.WriteLine("Executing the 'Foo' method...");
1641
service.Foo();
42+
```
1743

18-
// Resolving service...
19-
// Foo execution...
20-
// Hello from ctor
21-
// Hello from Foo
44+
The output for this example:
2245

2346
```
47+
Resolving the service...
48+
Executing the 'Foo' method...
49+
Ctor
50+
Foo
51+
```
52+
53+
## Features
2454

25-
The following is supported:
55+
Currently, `LazyProxy.Unity` supports the following:
2656
- Registration of types by interfaces;
2757
- Passing lifetime managers;
2858
- Passing injection members;
2959
- Resolving by child containers.
3060

31-
**Not supported yet:**
32-
- Registration of instances.
33-
3461
## Performance
3562

3663
Here is a result of the [Benchmark test](https://github.com/servicetitan/lazy-proxy-unity/blob/master/LazyProxy.Unity.Benchmarks/UnityExtensionBenchmark.cs)

0 commit comments

Comments
 (0)