-
Notifications
You must be signed in to change notification settings - Fork 5
Custom Configuration Provider #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shrey711
wants to merge
1
commit into
acamit:main
Choose a base branch
from
shrey711:CustomConfigProvider-Shrey
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
CustomConfigurationProvider/Controllers/CustomConfigurationController.cs
This file contains hidden or 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,27 @@ | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using YCompany.Configurations; | ||
|
|
||
| namespace CustomConfigurationProvider.Controllers | ||
| { | ||
| [Route("api/[controller]")] | ||
| [ApiController] | ||
| public class CustomConfigurationController : ControllerBase | ||
| { | ||
| private readonly IConfiguration _configuration; | ||
| public CustomConfigurationController(IConfiguration configuration) | ||
| { | ||
| _configuration = configuration; | ||
| } | ||
| [HttpGet] | ||
| public IActionResult Get() | ||
| { | ||
| var metadata = new SecurityMetaData | ||
| { | ||
| ApiKey = _configuration["ApiKey"], | ||
| ApiSecret = _configuration["ApiSecret"] | ||
| }; | ||
| return Ok(metadata); | ||
| } | ||
| } | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
CustomConfigurationProvider/CustomConfigurationExtensions.cs
This file contains hidden or 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,16 @@ | ||
| using Microsoft.Extensions.Configuration; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace YCompany.Configurations | ||
| { | ||
| public static class CustomConfigurationExtensions | ||
| { | ||
| public static IConfigurationBuilder AddSecurityConfiguration | ||
| (this IConfigurationBuilder builder) | ||
| { | ||
| return builder.Add(new CustomConfigurationSource()); | ||
| } | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
CustomConfigurationProvider/CustomConfigurationProvider.cs
This file contains hidden or 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,30 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using Microsoft.Extensions.Configuration; | ||
|
|
||
| namespace YCompany.Configurations | ||
| { | ||
| public class CustomConfigurationProvider :ConfigurationProvider | ||
| { | ||
| public override void Load() | ||
| { | ||
| var text = File.ReadAllText(@"D:\SecurityMetadata.json"); | ||
| var options = new JsonSerializerOptions | ||
| { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; | ||
| var content = JsonSerializer.Deserialize<SecurityMetaData> | ||
| (text, options); | ||
| if (content != null) | ||
| { | ||
| var Data = new Dictionary<string, string> | ||
| { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if there are more than 1 configurations in the json file? |
||
| {"ApiKey", content.ApiKey}, | ||
| {"ApiSecret", content.ApiSecret} | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
CustomConfigurationProvider/CustomConfigurationProvider.csproj
This file contains hidden or 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,13 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. configuration project should be a class library. not a web application |
||
| <PropertyGroup> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
4 changes: 4 additions & 0 deletions
4
CustomConfigurationProvider/CustomConfigurationProvider.csproj.user
This file contains hidden or 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,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <PropertyGroup /> | ||
| </Project> |
This file contains hidden or 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,16 @@ | ||
| using Microsoft.Extensions.Configuration; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace YCompany.Configurations | ||
| { | ||
| public class CustomConfigurationSource:IConfigurationSource | ||
|
|
||
| { | ||
| public IConfigurationProvider Build(IConfigurationBuilder builder) | ||
| { | ||
| return new CustomConfigurationProvider(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,29 @@ | ||
| using YCompany.Configurations; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| // Add services to the container. | ||
|
|
||
| builder.Configuration.AddSecurityConfiguration(); | ||
|
|
||
| builder.Services.AddControllers(); | ||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
| builder.Services.AddEndpointsApiExplorer(); | ||
| builder.Services.AddSwaggerGen(); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| // Configure the HTTP request pipeline. | ||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| app.UseSwagger(); | ||
| app.UseSwaggerUI(); | ||
| } | ||
|
|
||
| app.UseHttpsRedirection(); | ||
|
|
||
| app.UseAuthorization(); | ||
|
|
||
| app.MapControllers(); | ||
|
|
||
| app.Run(); |
31 changes: 31 additions & 0 deletions
31
CustomConfigurationProvider/Properties/launchSettings.json
This file contains hidden or 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,31 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "iisSettings": { | ||
| "windowsAuthentication": false, | ||
| "anonymousAuthentication": true, | ||
| "iisExpress": { | ||
| "applicationUrl": "http://localhost:57907", | ||
| "sslPort": 44305 | ||
| } | ||
| }, | ||
| "profiles": { | ||
| "CustomConfigurationProvider": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "launchUrl": "swagger", | ||
| "applicationUrl": "https://localhost:7007;http://localhost:5261", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "IIS Express": { | ||
| "commandName": "IISExpress", | ||
| "launchBrowser": true, | ||
| "launchUrl": "swagger", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,12 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace YCompany.Configurations | ||
| { | ||
| public class SecurityMetaData | ||
| { | ||
| public string ApiKey { get; set; } | ||
| public string ApiSecret { get; set; } | ||
| } | ||
| } |
This file contains hidden or 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,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controller is not requried in this project. this project will be referrenced in other project which will actually use the configuration provider.