小编kim*_*udi的帖子

ASP.NET Core Dependency Injection错误:尝试激活时无法解析类型服务

我创建了一个.NET Core MVC应用程序,并使用依赖注入和存储库模式将一个存储库注入我的控制器.但是,我收到一个错误:

InvalidOperationException:尝试激活"WebApplication1.Controllers.BlogController"时,无法解析类型"WebApplication1.Data.BloggerRepository"的服务.

型号(Blog.cs)

namespace WebApplication1.Models
{
    public class Blog
    {
        public int BlogId { get; set; }
        public string Url { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

DbContext(BloggingContext.cs)

using Microsoft.EntityFrameworkCore;
using WebApplication1.Models;

namespace WebApplication1.Data
{
    public class BloggingContext : DbContext
    {
        public BloggingContext(DbContextOptions<BloggingContext> options)
            : base(options)
        { }
        public DbSet<Blog> Blogs { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

存储库(IBloggerRepository.cs和BloggerRepository.cs)

using System;
using System.Collections.Generic;
using WebApplication1.Models;

namespace WebApplication1.Data
{
    internal interface IBloggerRepository : IDisposable
    {
        IEnumerable<Blog> GetBlogs();

        void InsertBlog(Blog blog);

        void …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection asp.net-core-mvc asp.net-core

146
推荐指数
13
解决办法
18万
查看次数

如何为Visual Studio 2017社区启用CodeLens

我最近安装了Visual Studio 2017社区,并注意到没有CodeLens.我在Visual Studio 2015社区上启用了CodeLens,所以我希望它也适用于VS 2017社区.我怎么能这样做?或者它不再适用于VS 2017社区版?

在Visual Studio 2015社区上启用CodeLens Visual Studio 2015社区上的CodeLens

codelens visual-studio-2017

38
推荐指数
2
解决办法
5万
查看次数

Material UI v5 中的 StylesProvider 与 StyledEngineProvider

我正在尝试从 Material-UI v4 迁移到 v5(目前处于测试阶段),但我不确定是否替换StylesProviderStyledEngineProvider. 没有提及它(请参阅https://next.material-ui.com/guides/migration-v4/)。迁移指南仅提到StylesProvider应直接从@material-ui/styles(而不是@material-ui/core/styles)导入。它还提到使用StyledEngineProviderwithinjectFirst选项来处理 css 顺序。然而,这就是为什么StylesProvider我需要使用StylesProvideror时我会感到困惑StyledEngineProvider

我用StyledEngineProvider代替吗StylesProvider?或者因为他们都做同样的事情所以并不重要?或者,StylesProvider如果我仍在使用 JSS,我是否需要使用,并且仅StyledEngineProvider当我不再使用 JSS 且仅使用 Emotion 时才使用?任何澄清将不胜感激。

material-ui

27
推荐指数
1
解决办法
2万
查看次数

如何从ASP.NET Core中的Razor View获取Url中的id值

我有一个简单的ASP.NET Core Web应用程序,其中包含这样的页面http://localhost:5050/Posts/Create/3.

在我的Razor View中Views/Posts/Create.cshtml,我如何能够获得值"3"以便我可以创建类似的链接<a href="/Blogs/Details/3">« Back to Blog</a>

到目前为止,使用以下Tag Helper创建了链接,但我不知道要放什么asp-route-id:

<a asp-controller="Blogs" asp-action="Details" asp-route-id="" class="btn btn-default btn pull-right">&laquo; Back</a>
Run Code Online (Sandbox Code Playgroud)

我只是使用默认的mvc路由:

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)

我知道我可以从模型(即,得到它Model.Blog.BlogId),但我希望从URL得到它使用类似Request.Query["id"]Views/Post/Create.cshtml.

我试过了asp-route-id="@Context.Request.Query["id"].

asp.net-core-mvc tag-helpers asp.net-core

8
推荐指数
4
解决办法
1万
查看次数

在 TypeScript 配置文件“tsconfig.json”中,将“lib”编译器选项设置为“dom”和“dom.iterable”是否多余?

根据有关编译器选项的 TypeScript 文档lib,在 TypeScript 配置文件中将lib编译器选项设置为 和dom是否多余?dom.iterabletsconfig.json

tsconfig.json

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable"],
  }
}
Run Code Online (Sandbox Code Playgroud)

我个人认为上述设置是多余的,但我见过很多使用上述选项的示例代码/博客文章。但由于我不确定,我想知道为什么上面的设置会用于以下设置:

{
  "compilerOptions": {
    "lib": ["dom"],
  }
}
Run Code Online (Sandbox Code Playgroud)

也许我只是吹毛求疵...或者也许有一个我不知道的正当理由为什么要同时指定domdom.iterable。如有任何澄清,我们将不胜感激。干杯!

typescript

8
推荐指数
1
解决办法
1616
查看次数

如何在Visual Studio for Mac中重置窗口布局

是否可以在Visual Studio for Mac中重置窗口布局?我可以在Windows上为Visual Studios执行此操作,但不能在Mac版本上执行此操作.

visual-studio-mac

7
推荐指数
1
解决办法
2130
查看次数

如何在 .NET 6 中强制使用小写路由?

我想在 .NET 6 API 项目中强制执行小写路由。

这是我的Program.cs

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
Run Code Online (Sandbox Code Playgroud)

这是我的WeatherForecastController.cs

using Microsoft.AspNetCore.Mvc;

namespace Weather.API.Controllers
{
    [ApiController]
    [Route("weatherforecast")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", …
Run Code Online (Sandbox Code Playgroud)

.net-6.0

7
推荐指数
1
解决办法
4948
查看次数

如果我的组件作为 ReactJS 中的 child prop 传递给布局组件,如何访问布局组件中的 prop?

我有一个Layout包含名为 的状态的组件isLightMode,我想将其作为 prop 传递给其他组件访问和使用。

这是我的Layout组件:

import React from 'react'
import Main from '../components/main'

export default class Layout extends React.Component {
  constructor(props) {
    super(props)
    this.state = { isLightMode: true }
    this.toggleTheme = this.toggleTheme.bind(this)
  }

  toggleTheme() {
    this.setState(state => ({
      isLightMode: !state.isLightMode,
    }))
  }

  render() {
    const { isLightMode } = this.state
    const { children } = this.props
    return (
      <div>
        <Navigation
          isLightMode={isLightMode}
          onToggleTheme={this.toggleTheme}
        />
        {children && <Main isLightMode={isLightMode}>{children}</Main>}
      </div>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

特别是,我有一个Home想要访问 …

javascript reactjs react-props

5
推荐指数
1
解决办法
3916
查看次数

我如何将<math.h>库添加到cmake?

我在我的源代码中包含了math.h库.但我无法编译.错误:**未定义引用'sqrt'**未定义引用'atan'

如何将"math.h"添加到cmakelists.txt?

cmake clion

4
推荐指数
1
解决办法
7183
查看次数

如果值是哈希符号(#),如何获取请求参数值

我有以下请求网址:

localhost:8080/MyApp/browse/alphabetical/result?startsWith=#&page=1&size=10&sort=title&order=asc
Run Code Online (Sandbox Code Playgroud)

注意请求参数"startsWith=#".

我无法获取请求参数"#"的值'startsWith'.相反,我得到一个空字符串("")作为'startsWith'请求参数的值.是否有任何可能的方法来获取"#"请求参数的值?

这不起作用: ${param.startsWith eq '#'}

这个工作: ${param.startsWith eq ''}

如果没有办法解决这个问题,我将不得不求助于使用startsWith=0 ... startsWith=9而不是startsWith=#我真正不想要的

java jsp

3
推荐指数
1
解决办法
2377
查看次数

使用Java将“2010-02-15T20:05:28.000Z”转换为GMT格式

我有一个类似于以下“2010-02-15T20:05:28.000Z”的字符串,我需要使用 Java 以 GMT 格式输出该字符串。

顺便说一句,我不知道日期当前采用什么格式。

java

2
推荐指数
1
解决办法
6235
查看次数