Skip to content

Commit

Permalink
Use simplified Program.cs - VetClinicPublic
Browse files Browse the repository at this point in the history
  • Loading branch information
canro91 committed Sep 2, 2024
1 parent 0686c2e commit 92b87fb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 109 deletions.
91 changes: 74 additions & 17 deletions VetClinicPublic/src/VetClinicPublic/Program.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,81 @@
using System;
using Microsoft.AspNetCore.Hosting;
using System.Reflection;
using MassTransit;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using VetClinicPublic;
using VetClinicPublic.Web.Interfaces;
using VetClinicPublic.Web.Services;

namespace VetClinicPublic
var builder = WebApplication.CreateBuilder(args);

Console.WriteLine("Run RabbitMQ in Docker if it's not already running.");
Console.WriteLine(">> docker run -p 5672:5672 -p 15672:15672 rabbitmq:management");

builder.Services.AddControllersWithViews();

// configure site settings
var siteSettings = builder.Configuration.GetSection("SiteSettings");
builder.Services.Configure<SiteConfiguration>(siteSettings);

// configure email sending
var mailserverConfig = builder.Configuration.GetSection("Mailserver");
builder.Services.Configure<MailserverConfiguration>(mailserverConfig);
builder.Services.AddSingleton<ISendEmail, SmtpEmailSender>();
builder.Services.AddSingleton<ISendConfirmationEmails, ConfirmationEmailSender>();

// configure MediatR
builder.Services.AddMediatR(config => config.RegisterServicesFromAssembly(typeof(Main).Assembly));

// configure messaging
var messagingConfig = builder.Configuration.GetSection("RabbitMq");
builder.Services.Configure<RabbitMqConfiguration>(messagingConfig);
builder.Services.AddScoped<IMessagePublisher, MassTransitMessagePublisher>();

builder.Services.AddMassTransit(x =>
{
public class Program
var rabbitMqConfiguration = messagingConfig.Get<RabbitMqConfiguration>();
x.SetKebabCaseEndpointNameFormatter();

x.AddConsumers(Assembly.GetExecutingAssembly());

x.UsingRabbitMq((context, cfg) =>
{
public static void Main(string[] args)
var port = (ushort)rabbitMqConfiguration.Port;
cfg.Host(rabbitMqConfiguration.Hostname, port, rabbitMqConfiguration.VirtualHost, h =>
{
CreateHostBuilder(args).Build().Run();

Console.WriteLine("Run RabbitMQ in Docker if it's not already running.");
Console.WriteLine(">> docker run -p 5672:5672 -p 15672:15672 rabbitmq:management");
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
h.Username(rabbitMqConfiguration.UserName);
h.Password(rabbitMqConfiguration.Password);
});

cfg.ConfigureEndpoints(context);
});
});
var app = builder.Build();

if (builder.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
// disabled because of docker setup required
//app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

public partial class Main
{
}
92 changes: 0 additions & 92 deletions VetClinicPublic/src/VetClinicPublic/Startup.cs

This file was deleted.

0 comments on commit 92b87fb

Please sign in to comment.