forked from ardalis/pluralsight-ddd-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use simplified Program.cs - VetClinicPublic
- Loading branch information
Showing
2 changed files
with
74 additions
and
109 deletions.
There are no files selected for viewing
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
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 | ||
{ | ||
} |
This file was deleted.
Oops, something went wrong.