첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestSolution.zip
0.01MB

[TestLibrary 프로젝트]

 

▶ DataController.cs

using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; 

namespace TestLibrary
{
    /// <summary>
    /// 데이터 컨트롤러
    /// </summary>
    [Route("[controller]")]
    public class DataController : Controller
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 구하기 - Get()

        /// <summary>
        /// 구하기
        /// </summary>
        /// <returns>문자열 열거 가능형</returns>
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "test1", "test2" };
        }

        #endregion
    }
}

 

728x90

 

[TestServer 프로젝트]

 

▶ Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using System.Reflection;

namespace TestServer
{
    /// <summary>
    /// 시작
    /// </summary>
    public class Startup
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 구성 - Configuration

        /// <summary>
        /// 구성
        /// </summary>
        public IConfiguration Configuration { get; }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - Startup(configuration)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="configuration">구성</param>
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 서비스 컬렉션 구성하기 - ConfigureServices(serviceCollection)

        /// <summary>
        /// 서비스 컬렉션 구성하기
        /// </summary>
        /// <param name="serviceCollection">서비스 컬렉션</param>
        public void ConfigureServices(IServiceCollection serviceCollection)
        {
            serviceCollection.AddControllers()
                .AddApplicationPart(Assembly.Load(new AssemblyName("TestLibrary")));

            serviceCollection.AddSwaggerGen
            (
                option =>
                {
                    option.SwaggerDoc("v1", new OpenApiInfo { Title = "TestServer", Version = "v1" });
                }
            );
        }

        #endregion
        #region 구성하기 - Configure(applicationBuilder, environment)

        /// <summary>
        /// 구성하기
        /// </summary>
        /// <param name="builder">애플리케이션 빌더</param>
        /// <param name="environment">웹 호스트 환경</param>
        public void Configure(IApplicationBuilder builder, IWebHostEnvironment environment)
        {
            if(environment.IsDevelopment())
            {
                builder.UseDeveloperExceptionPage();

                builder.UseSwagger();

                builder.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TestServer v1"));
            }

            builder.UseHttpsRedirection();

            builder.UseRouting();

            builder.UseAuthorization();

            builder.UseEndpoints
            (
                endpoints =>
                {
                    endpoints.MapControllers();
                }
            );
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요