Advertisement
Guest User

Untitled

a guest
May 27th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.Identity;
  8. using Microsoft.EntityFrameworkCore;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Swashbuckle.AspNetCore.Swagger;
  12. using YourCalendar.Data;
  13. using YourCalendar.Models;
  14. using YourCalendar.Services;
  15.  
  16. namespace YourCalendar
  17. {
  18. public class Startup
  19. {
  20. public Startup(IConfiguration configuration)
  21. {
  22. Configuration = configuration;
  23. }
  24.  
  25. public IConfiguration Configuration { get; }
  26.  
  27. // This method gets called by the runtime. Use this method to add services to the container.
  28. public void ConfigureServices(IServiceCollection services)
  29. {
  30. services.AddDbContext<CalendarContext>(options =>
  31. options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
  32.  
  33. services.AddIdentity<ApplicationUser, IdentityRole>()
  34. .AddEntityFrameworkStores<CalendarContext>()
  35. .AddDefaultTokenProviders();
  36.  
  37. // Add application services.
  38. services.AddTransient<IEmailSender, EmailSender>();
  39.  
  40. services.AddMvc();
  41.  
  42. // Register the Swagger generator, defining one or more Swagger
  43. // documents
  44. services.AddSwaggerGen(c =>
  45. {
  46.  
  47. c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
  48.  
  49. });
  50. }
  51.  
  52. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  53. public void Configure(
  54. IApplicationBuilder app,
  55. IHostingEnvironment env,
  56. CalendarContext context)
  57. {
  58. if (env.IsDevelopment())
  59. {
  60. app.UseDeveloperExceptionPage();
  61. app.UseDatabaseErrorPage();
  62. }
  63. else
  64. {
  65. app.UseExceptionHandler("/Home/Error");
  66. }
  67.  
  68. app.UseStaticFiles();
  69.  
  70. app.UseAuthentication();
  71.  
  72. // Enable middleware to serve generated Swagger as JSON endpoint
  73.  
  74. app.UseSwagger();
  75.  
  76. // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.)
  77. // specifying the Swagger JSON endpoint.
  78.  
  79. app.UseSwaggerUI(c =>
  80. {
  81. c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
  82. });
  83.  
  84. app.UseMvc(routes =>
  85. {
  86. routes.MapRoute(
  87. "SubscribeMovie", // Route name
  88. "{controller}/{action}/{movieId}/{userId}", // URL with parameters
  89. new { controller = "Movies", action = "Subscribe", movieId = 0, userId = "" } // Parameter defaults
  90. );
  91.  
  92. routes.MapRoute(
  93. name: "default",
  94. template: "{controller=Home}/{action=Index}/{id?}");
  95.  
  96.  
  97. });
  98.  
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement