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
Log.Logger = new LoggerConfiguration() | |
.WriteTo.Async(wt => wt.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Properties:j}{NewLine}{Exception}")) | |
.CreateLogger(); |
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
var logLevel = builder.Environment.IsProduction() ? LogEventLevel.Warning : LogEventLevel.Debug; | |
Log.Logger = new LoggerConfiguration() | |
.WriteTo.Async(wt => wt.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Properties:j}{NewLine}{Exception}", restrictedToMinimumLevel: logLevel)) | |
.CreateLogger(); |
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
using Serilog; | |
using Serilog.BestPractices.Extensions; | |
try | |
{ | |
var builder = WebApplication.CreateBuilder(args); | |
builder.AddSerilogApi(); | |
builder.Services.AddControllers(); |
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
[Route("api/[controller]")] | |
public class SampleController : Controller | |
{ | |
private readonly OpenAIAPI _chatGpt; | |
public SampleController(OpenAIAPI chatGpt) | |
{ | |
_chatGpt = chatGpt; | |
} |
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
public static class ChatGptExtensions | |
{ | |
public static WebApplicationBuilder AddChatGpt(this WebApplicationBuilder builder, IConfiguration configuration) | |
{ | |
var key = configuration["ChatGpt:Key"]; | |
var chat = new OpenAIAPI(key); | |
builder.Services.AddSingleton(chat); |
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
using Microsoft.AspNetCore.Builder; | |
using Microsoft.Extensions.DependencyInjection; | |
using Sample.ChatGpt.WebApi.Core.Extensions; | |
using Sample.ChatGpt.WebApi.Core.Middleware; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.AddSerilog(builder.Configuration, "Sample ChatGPT"); | |
builder.AddChatGpt(builder.Configuration); | |
builder.Services.AddRouting(options => options.LowercaseUrls = true); |
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
var builder = WebApplication.CreateBuilder(args); | |
builder.AddSerilog(builder.Configuration, "Sample Scrutor"); | |
Log.Information("Starting API"); | |
builder.Services.AddControllers(); | |
builder.Services.AddEndpointsApiExplorer(); | |
builder.Services.AddSwaggerGen(); | |
builder.Services.AddClassesMatchingInterfaces(nameof(Sample)); |
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
services.Scan(scan => scan | |
.FromAssembliesOf(typeof(IUserService)) | |
.AddClasses(classes => classes.Where(type => type.Name.EndsWith("Service"))) | |
.AsSelf() | |
.WithScopedLifetime()); |
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
services.Scan(scan => scan | |
.FromAssembliesOf(typeof(IUserService)) | |
.AddClasses(classes => classes.HavingAttribute<CustomServiceAttribute>()) | |
.AsImplementedInterfaces() | |
.WithScopedLifetime()); |
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
services.AddScoped<ICustomerService, CustomerService>(); | |
services.AddScoped<IUserService, UserService>(); | |
services.AddScoped<IBusinessService, BusinessService>(); |