PDA

View Full Version : سوال: مشکل با IserviceProvider.Getservice



asma65
شنبه 06 آبان 1396, 11:50 صبح
سلام من تازه دارم mvc یاد میگیرم تو آموزشام چنین کدی دارم
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Extensions.DependencyInjection;


namespace MysecondTestMvc.Models
{
public static class SeedData
{
public static void Initialize(IServiceProvider serviceProvider)
{


var context = serviceProvider.GetService<ApplicationDbContext>(); //if (context.Database == null) { throw new Exception("DB is null"); } //if (context.Movie.Any()) { return; // DB has been seeded }
}
}
}

من یه کلاس روscaffold کردم
تو این خط
var context = serviceProvider.GetService<ApplicationDbContext>();
روی ApplicationDbContext این خطا رومیده
the non-generic method "IServiceProvider.GetService(Type)" can not be used withe type arguments

سرویس مربوط روتو ذفرنس ها اضافه کردم و namespace مورد نظر رو هم به کلاس

using Microsoft.Extensions.DependencyInjection;

ممنون