【发布时间】:2021-02-23 18:47:46
【问题描述】:
现在我正在开发 Web api Asp.net 核心,但我对 DI 感到困惑。 当我尝试向我的 api 发送请求时,出现此错误
我使用 Ninject,我认为我对此有疑问 GitLab 和我的项目https://gitlab.com/ValeriiDmytryshyn/sharedocument
启动文件可能有问题
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DocumentContext>
(options => options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));
services.AddControllers();
var mappingConfig = new MapperConfiguration(mc =>
{
mc.AddProfile(new AutomapperProfile());
});
IMapper mapper = mappingConfig.CreateMapper();
services.AddSingleton(mapper);
services.AddMvc();
NinjectModule ninjectModule = new NinjModule();
NinjectModule serviceModule = new ServiceModule(Configuration["ConnectionStrings:DefaultConnection"]);
var kernel = new StandardKernel(ninjectModule, serviceModule);
DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
【问题讨论】:
-
好的对不起我会编辑它
标签: c# api asp.net-web-api