您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. }