-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
## Usage | ||
|
||
```c# | ||
|
||
//C#11(NET7+) support generic attribute | ||
[AutoDto<T>(ServiceLifetime.Scoped)] | ||
|
||
``` | ||
|
||
### Your Service | ||
|
||
```c# | ||
|
||
public interface ITestService | ||
{ | ||
string Say(string message); | ||
} | ||
|
||
public interface ITest2Service | ||
{ | ||
string Say2(string message); | ||
} | ||
|
||
[AutoInject<TestService>] | ||
[AutoInject<ITestService>(ServiceLifetime.Singleton)] | ||
//[AutoInject<ITest2Service>(ServiceLifetime.Scoped)] | ||
public class TestService : ITestService, ITest2Service | ||
{ | ||
public string Say(string message) | ||
{ | ||
return $"hello {message}"; | ||
} | ||
|
||
public string Say2(string message) | ||
{ | ||
return message; | ||
} | ||
} | ||
|
||
[AutoInject<ITest2Service>] | ||
public class TestService2 : ITest2Service | ||
{ | ||
public string Say2(string message) | ||
{ | ||
return message; | ||
} | ||
} | ||
|
||
|
||
``` | ||
|
||
|
||
### Enjoy | ||
|
||
```c# | ||
// <auto-generated /> | ||
#pragma warning disable | ||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
using Biwen.AutoClassGen.TestConsole.Services; | ||
|
||
public static class ServiceCollectionExtension | ||
{ | ||
/// <summary> | ||
/// 自动注册标注的服务 | ||
/// </summary> | ||
/// <param name = "services"></param> | ||
/// <returns></returns> | ||
public static IServiceCollection AddAutoInject(this IServiceCollection services) | ||
{ | ||
services.AddScoped<TestService>(); | ||
services.AddSingleton<ITestService, TestService>(); | ||
services.AddScoped<ITest2Service, TestService2>(); | ||
return services; | ||
} | ||
} | ||
} | ||
#pragma warning restore | ||
``` | ||
|
||
### Then .AddAutoInject() | ||
|
||
- 服务将自动注册到DI容器中 | ||
|
||
```c# | ||
|
||
// add auto inject | ||
builder.Services.AddAutoInject(); | ||
|
||
``` | ||
|
||
|
||
### Report Diagnostic Code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters