-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 移除IScopedDependence等接口,添加KeyedService支持.
- Loading branch information
Showing
8 changed files
with
102 additions
and
123 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
sample/WebApi.Test.Unit/Controllers/KeyedServiceTestController.cs
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,69 @@ | ||
using EasilyNET.AutoDependencyInjection.Core.Attributes; | ||
using EasilyNET.WebCore.Swagger.Attributes; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
// ReSharper disable ClassNeverInstantiated.Global | ||
|
||
namespace WebApi.Test.Unit.Controllers; | ||
|
||
/// <summary> | ||
/// KeyedServiceTest | ||
/// </summary> | ||
[Route("api/[controller]"), ApiController, ApiGroup("KeyedServiceTest", "v1", "KeyedServiceTestController")] | ||
public class KeyedServiceTestController(IServiceProvider sp, IKeyedServiceTest kst2) : ControllerBase | ||
{ | ||
/// <summary> | ||
/// ShowHello | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpGet("HelloKeyedService")] | ||
public string ShowHello() | ||
{ | ||
var kst = sp.GetRequiredKeyedService<KeyedServiceTest>("helloKey"); | ||
return kst.ShowHello(); | ||
} | ||
|
||
/// <summary> | ||
/// ShowHello2 | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpGet("HelloKeyedService2")] | ||
public string ShowHello2() => kst2.ShowHello(); | ||
|
||
/// <summary> | ||
/// ShowHello3 | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpGet("HelloKeyedService3")] | ||
public string ShowHello3() | ||
{ | ||
var kst = sp.GetRequiredKeyedService<IKeyedServiceTest>("helloKey"); | ||
return kst.ShowHello(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// KeyedServiceTest | ||
/// </summary> | ||
[DependencyInjection(ServiceLifetime.Transient, ServiceKey = "helloKey")] | ||
public sealed class KeyedServiceTest : IKeyedServiceTest | ||
{ | ||
/// <summary> | ||
/// ShowHello | ||
/// </summary> | ||
/// <returns></returns> | ||
// ReSharper disable once MemberCanBeMadeStatic.Global | ||
public string ShowHello() => "Hello, KeyedServiceTest!"; | ||
} | ||
|
||
/// <summary> | ||
/// IKeyedServiceTest | ||
/// </summary> | ||
public interface IKeyedServiceTest | ||
{ | ||
/// <summary> | ||
/// ShowHello | ||
/// </summary> | ||
/// <returns></returns> | ||
string ShowHello(); | ||
} |
12 changes: 0 additions & 12 deletions
12
src/EasilyNET.AutoDependencyInjection.Core/Abstractions/IScopedDependency.cs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/EasilyNET.AutoDependencyInjection.Core/Abstractions/ISingletonDependency.cs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/EasilyNET.AutoDependencyInjection.Core/Abstractions/ITransientDependency.cs
This file was deleted.
Oops, something went wrong.
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
2 changes: 2 additions & 0 deletions
2
src/EasilyNET.AutoDependencyInjection.Core/Attributes/IgnoreDependencyAttribute.cs
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