-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add sample project about dependency injection via constructor
- Loading branch information
1 parent
e76cb3b
commit 1d0a085
Showing
9 changed files
with
85 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Example.Contracts; | ||
|
||
public interface ITestService | ||
{ | ||
string Execute(); | ||
} |
10 changes: 10 additions & 0 deletions
10
samples/HostApplications/WebApi/Controllers/ServiceController.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,10 @@ | ||
namespace Example.HostWebApi.Controllers; | ||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
public class ServiceController | ||
{ | ||
[HttpGet] | ||
public ActionResult<string> Get(ITestService service) | ||
=> service.Execute(); | ||
} |
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
9 changes: 9 additions & 0 deletions
9
samples/Plugins/DependencyInjectionPlugin/Example.DependencyInjectionPlugin.csproj
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<OutDir>$(WebApiProjectDir)</OutDir> | ||
<OutputType>Library</OutputType> | ||
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,3 @@ | ||
global using Example.Contracts; | ||
global using CPlugin.Net; | ||
global using Example.DependencyInjectionPlugin; |
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,23 @@ | ||
[assembly: Plugin(typeof(TestService))] | ||
|
||
namespace Example.DependencyInjectionPlugin; | ||
|
||
public class TestService : ITestService | ||
{ | ||
private readonly ILogger<TestService> _logger; | ||
private readonly IConfiguration _configuration; | ||
|
||
public TestService( | ||
ILogger<TestService> logger, | ||
IConfiguration configuration) | ||
{ | ||
_logger = logger; | ||
_configuration = configuration; | ||
} | ||
|
||
public string Execute() | ||
{ | ||
_logger.LogInformation("TestService"); | ||
return _configuration["ServiceName"]; | ||
} | ||
} |
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