Beispiel #1
0
        // 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 https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            var authoptions = _config.GetSection("Auth").Get <AuthOptions>();

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(
                option =>
            {
                option.RequireHttpsMetadata      = true;
                option.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer = true,
                    ValidIssuer    = authoptions.Issuer,

                    ValidateAudience = true,
                    ValidAudience    = authoptions.Audience,

                    ValidateLifetime = true,

                    IssuerSigningKey         = authoptions.GetSymmetricSecurityKey(),
                    ValidateIssuerSigningKey = true
                };
            });
            services.AddCors(options =>
            {
                options.AddDefaultPolicy(
                    builder => builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader());
            });
            DbContextInstaller.ConfigureDbContext(services);
            ServiceInstaller.ConfigureServices(services);
            services
            .AddSingleton <IMapper>(new Mapper(GetMapperConfiguration()));
        }
Beispiel #2
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var services = new ServiceCollection();

            DbContextInstaller.ConfigureDbContext(services);
            SchedulerDbContext db = new SchedulerDbContext(new DbContextOptions <SchedulerDbContext>());
            Task task             = new Task();

            task.Name = "Пописать";
            User usere = new User();

            usere.Task = new List <Task>();
            usere.Task.Add(task);
            usere.Name     = "Валентин Дядька";
            usere.Email    = "*****@*****.**";
            usere.Password = "******";
            //db.Userses.Find(1).Task.Remove(db.Userses.Find(1).Task.Find(t=>t.Id==2)); // я понимаю, что при таком подходе в бд всё равно останется задача. Оно и к лучшему. Будет что фсб показать
            db.Userses.Add(usere);
            db.Taskses.Add(task);
            db.SaveChanges();
            foreach (var user in db.Userses.ToList())
            {
                Console.WriteLine($"{user.Id}.{user.Name}+{user.Password}");
                //Console.WriteLine($"{first}");
            }
        }
        /// <summary>
        /// Registers the type mappings with the Unity container.
        /// </summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>
        /// There is no need to register concrete types such as controllers or
        /// API controllers (unless you want to change the defaults), as Unity
        /// allows resolving a concrete type even if it was not previously
        /// registered.
        /// </remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DrinkVendingMachine"].ConnectionString;

            DbContextInstaller.Install(container, new PerRequestLifetimeManager(), connectionString);
            MigratorInstaller.Install(container, connectionString);
            DataServiceInstaller.Install(container);
        }
Beispiel #4
0
        // 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 https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            var authOptionsConfiguration = Configuration.GetSection("Auth");

            services.Configure <AuthOptions>(authOptionsConfiguration);

            services.AddCors(options =>
            {
                options.AddDefaultPolicy(
                    builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader();
                });
            });
            DbContextInstaller.ConfigureDbContext(services);
            ServicesInstaller.ConfigureServices(services);
            services
            .AddSingleton <IMapper>(new Mapper(GetMapperConfiguration()));
        }