// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { // Add Entity Framework services to the services container. services.AddEntityFramework() .AddSqlServer() .AddDbContext <PhotoGalleryContext>(options => options.UseSqlServer(Configuration["Data:PhotoGalleryConnection:ConnectionString"])); // Repositories services.AddScoped <IPhotoRepository, PhotoRepository>(); services.AddScoped <IAlbumRepository, AlbumRepository>(); services.AddScoped <IUserRepository, UserRepository>(); services.AddScoped <IUserRoleRepository, UserRoleRepository>(); services.AddScoped <IRoleRepository, RoleRepository>(); services.AddScoped <ILoggingRepository, LoggingRepository>(); // Services services.AddScoped <IMembershipService, MembershipService>(); services.AddScoped <IEncryptionService, EncryptionService>(); services.AddAuthentication(); // Polices services.AddAuthorization(options => { // inline policies options.AddPolicy("AdminOnly", policy => { policy.RequireClaim(ClaimTypes.Role, "Admin"); }); }); // Add MVC services to the services container. services.AddMvc(); }
public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.Configure <SessionOptions>(option => option.IdleTimeout = TimeSpan.FromMinutes(30)); services.AddCaching(); services.AddSession(); services.AddMvc(); services.Configure <MvcOptions>(Router.Instance.Route); services.Configure <MvcOptions>(options => { //options.Filters.Add(typeof(ActionFilter)); //options.Filters.Add(typeof(ResultFilter)); //options.Filters.Add(typeof(AuthorizationFilter)); options.Filters.Add(typeof(ExceptionFilter)); }); services.AddEntityFramework().AddSqlServer().AddDbContext <ApplicationDbContext>(); }