Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddMvc(options =>
            //{
            //    options.Filters.Add(typeof(ValidateModelStateAttribute));
            //}).AddJsonOptions(o => o.SerializerSettings.NullValueHandling = NullValueHandling.Ignore)
            //    .ConfigureApiBehaviorOptions(options =>
            //    {
            //        options.SuppressMapClientErrors = true;
            //        options.SuppressModelStateInvalidFilter = true;
            //    });

            services.AddControllersWithViews();

            /*
             * Transient : Her istendiğinde oluşturulur.
             * Scoped    : istemci isteği (bağlantı) başına bir kez oluşturulur.
             * Singleton : Sonraki her istek aynı örneği kullanır.
             *
             *
             * dotnet tool install --global dotnet-ef --version 3.1.3
             * dotnet ef migrations remove
             * dotnet ef database update
             * dotnet ef migrations add InitialCreate
             */

            services.AddDbContext <DbContext, TodoContext>(x => x.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddScoped <ITodoProvider, TodoProvider>();
            services.AddScoped <ITodoService, TodoService>();


            AutoMapperExtensions.Init(MappingConfiguration.InitializeAutoMapper().CreateMapper());
        }