-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global.asax.cs
68 lines (56 loc) · 2.88 KB
/
Global.asax.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
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 System;
using System.Data.SqlClient;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Autofac;
using Autofac.Integration.Mvc;
using NServiceBus;
using NServiceBus.Persistence.Sql;
namespace NSB6SelfHostedClientMVC
{
public class MvcApplication : System.Web.HttpApplication
{
private IEndpointInstance endpoint;
protected void Application_Start()
{
const string connectionString = "UseDevelopmentStorage=true";
var endpointConfiguration = new EndpointConfiguration("NSB6SelfHostedClientMVCAzureTransportAndPersistence");
endpointConfiguration.SendOnly();
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var connection = @"Data Source=sql; Initial Catalog=NsbSqlPersistence; Integrated Security=False; User ID=sa; Password=Password123!; Connect Timeout=60; Encrypt=False;";
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new SqlConnection(connection);
});
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
var transportSettings = endpointConfiguration.UseTransport<AzureStorageQueueTransport>();
transportSettings.ConnectionString(connectionString);
transportSettings.DelayedDelivery().DisableTimeoutManager();
var delayedDelivery = transportSettings.DelayedDelivery();
delayedDelivery.UseTableName("delaysNSB6SelfHostedClientMVC");
var routingSettings = transportSettings.Routing();
routingSettings.RouteToEndpoint(typeof(NSB6SelfHostedClientMVC.Messages.Commands.TestCommand), "NSB6SelfHostedClientMVC.Handlers");
endpointConfiguration.UseSerialization<JsonSerializer>();
endpointConfiguration.SendFailedMessagesTo("error");
endpointConfiguration.AuditProcessedMessagesTo("audit");
endpoint = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
var mvcContainerBuilder = new ContainerBuilder();
mvcContainerBuilder.RegisterInstance(endpoint);
mvcContainerBuilder.RegisterControllers(typeof(MvcApplication).Assembly);
var mvcContainer = mvcContainerBuilder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(mvcContainer));
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
protected void Application_End()
{
endpoint?.Stop().GetAwaiter().GetResult();
}
}
}