Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

61 rinda
1.7 KiB

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