Skip to content

Commit 544a6de

Browse files
authored
housekeeping: Update readme
1 parent aa689dc commit 544a6de

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,76 @@
1-
# Splat.DI.SourceGenerator
1+
# Splat Source Generator
2+
3+
This project is a source generator which produces Splat based registrations for both constructor and property injection.
4+
5+
# Installation
6+
7+
## NuGet Packages
8+
9+
Make sure your project is using the newer `PackageReference` inside your CSPROJ. The older style is buggy and should be moved away from regardless. See here for discussions how to [upgrade](https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference).
10+
11+
Install the following packages:
12+
13+
| Name | Platform | NuGet |
14+
| ----------------------------- | ----------------- | -------------------------------- |
15+
| [Splat.DependencyInjection.SourceGenerator][Core] | Core - Libary | [![CoreBadge]][Core] |
16+
17+
18+
[Core]: https://www.nuget.org/packages/Splat.DependencyInjection.SourceGenerator/
19+
[CoreBadge]:https://img.shields.io/nuget/v/Splat.DependencyInjection.SourceGenerator.svg
20+
21+
## What does it do?
22+
23+
ObservableEvents generator registrations for Splat based on your constructors and properties. It will not use reflection and instead uses Source Generation. You should get full native speed.
24+
25+
## Installation
26+
Include the following in your .csproj file
27+
28+
```xml
29+
<PackageReference Include="Splat.DependencyInjection.SourceGenerator" Version="{latest version}" PrivateAssets="all" />
30+
```
31+
32+
The `PrivateAssets` will prevent the Source generator from being inherited into other projects.
33+
34+
## How to use
35+
36+
### Registration
37+
38+
Register your dependencies using the `SplatRegistrations` class.
39+
40+
There are two methods.
41+
42+
`Register()` will generate a new instance each time. Use generic parameters, first for the interface type, second for the concrete type.
43+
44+
```cs
45+
SplatRegistrations.Register<IMenuUseCase, MenuUseCase>();
46+
SplatRegistrations.Register<IOtherDependency, OtherDependency>();
47+
```
48+
49+
`RegisterLazySingleton()` will have a lazy instance. Use generic parameters, first for the interface type, second for the concrete type.
50+
51+
```cs
52+
SplatRegistrations.RegisterLazySingleton<IMessagesSqlDataSource, MessagesSqlDataSource>();
53+
```
54+
55+
### Constructor Injection
56+
If there are more than one constructor use the `[DependencyInjectionConstructor]` attribute to signify which one should be used.
57+
58+
```cs
59+
[DependencyInjectionConstructor]
60+
public AuthApi(
61+
Lazy<IJsonService> jsonService,
62+
: base(jsonService)
63+
{
64+
}
65+
```
66+
67+
### Property Injection
68+
69+
Use the `[DependencyInjectionProperty]` above a property to be initialized. It must be `public` or `internal` setter.
70+
71+
```cs
72+
public class MySpecialClass
73+
{
74+
[DependencyInjectionProperty]
75+
public IService MyService { get; set; }
76+
}

0 commit comments

Comments
 (0)