You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

55 lines
1.5 KiB

  1. using DotNetCore.CAP;
  2. using Microsoft.AspNetCore.Builder;
  3. using Microsoft.AspNetCore.Hosting;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using MongoDB.Driver;
  8. namespace Sample.RabbitMQ.MongoDB
  9. {
  10. public class Startup
  11. {
  12. public Startup(IConfiguration configuration)
  13. {
  14. Configuration = configuration;
  15. }
  16. public IConfiguration Configuration { get; }
  17. public void ConfigureServices(IServiceCollection services)
  18. {
  19. services.AddSingleton<IMongoClient>(new MongoClient(Configuration.GetConnectionString("MongoDB")));
  20. services.AddCap(x =>
  21. {
  22. x.UseMongoDB();
  23. var mq = new RabbitMQOptions();
  24. Configuration.GetSection("RabbitMQ").Bind(mq);
  25. x.UseRabbitMQ(cfg =>
  26. {
  27. cfg.HostName = mq.HostName;
  28. cfg.Port = mq.Port;
  29. cfg.UserName = mq.UserName;
  30. cfg.Password = mq.Password;
  31. });
  32. x.UseDashboard();
  33. });
  34. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  35. }
  36. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  37. {
  38. if (env.IsDevelopment())
  39. {
  40. app.UseDeveloperExceptionPage();
  41. }
  42. app.UseMvc();
  43. app.UseCap();
  44. }
  45. }
  46. }