Overview : NetCore 6.0 기준으로 아래와 같이 나오게 하기
![](https://mvc.auctionpro.co.kr/wp-content/uploads/2024/06/image-1-1024x558.png)
1.csproj 파일을 Edit로 열어 PropertyGroup 에 추가
1 2 3 4 |
<GenerateDocumentationFile>true</GenerateDocumentationFile> <NoWarn>$(NoWarn);1591</NoWarn> |
추가후 내용 및 설명
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <OutputType>Exe</OutputType> <GenerateDocumentationFile>true</GenerateDocumentationFile> <NoWarn>$(NoWarn);1591</NoWarn> </PropertyGroup> ::: 아래 생략 :: |
![](https://mvc.auctionpro.co.kr/wp-content/uploads/2024/06/image-2.png)
<GenerateDocumentationFile>true</GenerateDocumentationFile>:
- XML 문서 파일 생성을 활성화합니다. 코드 내 XML 주석을 기반으로 문서 파일을 생성합니다.
<NoWarn>$(NoWarn);1591</NoWarn>:
- 특정 경고를 무시하도록 설정합니다. 여기서 1591 경고는 “XML 주석이 없는 공개 멤버”에 대한 경고이며, 이를 무시하도록 설정합니다.
2.Program.cs 아래와 수정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
builder.Services.AddControllers().AddXmlDataContractSerializerFormatters(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "MemoryCache MsSQL MySQL", Version = "1.0", Description = "메모리 캐싱 테스트 Json", TermsOfService = new Uri("https://www.auctionpro.co.kr"), Contact = new OpenApiContact { Email = "noreply@auctionpro.co.kr" }, License = new OpenApiLicense { Name = "라이센스", Url = new Uri("https://www.auctionpro.co.kr") } }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MemoryCache MsSQL MySQL v1")); } |
최종 내용 예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
using InMemoryCacheCore.Infrastructure.V01; using InMemoryCacheCore.Services02.V13; using Microsoft.OpenApi.Models; using System.Reflection; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddHttpClient(); builder.Services.AddScoped<ICacheProvider, CacheProvider>(); //infrastructure builder.Services.AddScoped<IHttpClient, InMemoryCacheCore.Infrastructure.V01.HttpClient>(); //infrastructure builder.Services.AddScoped<ICacheGetSet, CacheGetSet>(); //추가 builder.Services.AddScoped<ICacheGetSet, CacheGetSet>(); //추가 builder.Services.AddMemoryCache(); builder.Services.AddControllers().AddXmlDataContractSerializerFormatters(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "MemoryCache MsSQL MySQL", Version = "1.0", Description = "메모리 캐싱 테스트 Json", TermsOfService = new Uri("https://www.auctionpro.co.kr"), Contact = new OpenApiContact { Email = "noreply@auctionpro.co.kr" }, License = new OpenApiLicense { Name = "라이센스", Url = new Uri("https://www.auctionpro.co.kr") } }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MemoryCache MsSQL MySQL v1")); } //if (!app.Environment.IsDevelopment()) //{ app.UseHttpsRedirection(); //} app.UseAuthorization(); app.MapControllers(); app.Run(); |
3.Controller.cs 에 아래 내용 추가
1 2 3 4 5 6 7 8 |
/// <summary> /// 공항코드 가져오기 /// </summary> /// <param name="AAA"><font color='red'>*</font>AAA값 설명</param> /// <param name="BBB">BBB값 설명</param> /// <returns></returns> |
최종 내용 예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
using InMemoryCacheCore.Models; using InMemoryCacheCore.Services02.V13; using Microsoft.AspNetCore.Mvc; namespace InMemoryCacheCore.Controllers { [Route("api/[controller]")] [ApiController] public class AirlineController : ControllerBase { private readonly ICacheGetSet _cacheGetSet; private readonly string _cacheKey = "_ACode"; public AirlineController(ICacheGetSet cacheGetSet ) { _cacheGetSet = cacheGetSet ?? throw new ArgumentNullException(nameof(cacheGetSet)); } /// <summary> /// 공항코드 가져오기 /// </summary> /// <param name="AAA"><font color='red'>*</font>AAA값 설명</param> /// <param name="BBB">BBB값 설명</param> /// <returns></returns> [HttpGet] public async Task<IEnumerable<Code>> Get(string AAA, string BBB) { try { IEnumerable<Code>? codes = await _cacheGetSet.CacheGet(_cacheKey); return codes; } catch { return Enumerable.Empty<Code>(); } } } } |