考虑以下代码:
public class Test
{
public async Task Do()
{
await Task.Delay(200);
using (var disposable = new Disposable())
{
disposable.Do();
}
}
}
public class Disposable : IDisposable
{
public void Do()
{
}
public void Dispose()
{
}
}
Run Code Online (Sandbox Code Playgroud)
当我在Visual Studio中运行代码分析时,我收到一个警告:
警告CA1001在测试时实现IDisposable.<Do> d__0因为它创建了以下IDisposable类型的成员:'Disposable'.
为什么我收到此消息?一次性类正确处理,我不会将它存储在任何地方.
此外,这似乎适用于分析仪:
public class Test
{
public void Do()
{
using (var disposable = new Disposable())
{
disposable.Do();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想在消耗处理率高卡夫卡队列,并利用.NET 2.1的核心我试图同时使用EF结果存储在MySQL的AddDbContext和AddDbContextPool我跑在这两种情况下进入的问题。
1)当使用AddDbContext我成功的唯一方法是确定它的范围时,每次我需要调用数据插入时都会transient获得一个新DataContext实例。我的队列很大,最终与 mqSQL 服务器的连接太多,所以最终我开始收到大量超时错误。
我知道我可以添加选项来重试瞬态错误(超时就是其中之一),但我最感兴趣的是如何将DataContext实例数量减少到不会破坏数据库的数量。这让我进行了下一次尝试
2)使用时AddDbContextPool我无法将范围设置为transient找不到语法!有吗?无法为每次调用都获得一个新实例我会遇到另一种奇怪的错误,这些错误通常可以通过短暂的生命周期解决
An attempt was made to use the context while it is being configured.
A DbContext instance cannot be used inside OnConfiguring since it is still being configured at this point.
This can happen if a second operation is started on this context before a previous operation completed.
Any instance members are not guaranteed to be thread safe. …
c# entity-framework dbcontext entity-framework-core .net-core
每当我尝试使用 Resharper 从构造函数值生成属性时:
那么该属性总是在构造函数之上生成:
public class MyClass
{
public int Value { get; }
public MyClass(int value)
{
this.Value = value;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以强制 Resharper 在构造函数下生成它们吗?
编辑:
我的文件布局设置似乎没问题:
我正在尝试使用 Visual studio 2017 为在 Linux 容器上运行的 .net core 2.0 Web 应用程序运行 docker 支持。我正在使用 win 7 操作系统的机器上工作,所以我必须使用带有 Virtual box 的 Docker 工具箱。我已经检查过这个问题:How to get docker toolbox to work with .net core 2.0 project,但是当尝试使用 VS 运行它时,我遇到了以下问题:
未启用卷共享。在 docker ce for windows 设置中启用卷共享
到目前为止,我知道 C:\Users 下安装了一个默认卷,因此我的项目文件应该复制到此文件夹下的某个位置,以防我不想安装任何其他卷。所以我把它们复制到那里。
当我检查虚拟盒子的设置时,文件夹似乎已共享:
我什至可以使用命令行 cd 进入该文件夹,但仍然无法解决这个问题。对此有什么想法吗?
我想知道无论如何,如何使用Ninject进行参数存在检查?
我指的是:让我们有一个理论类和一个接口:
public interface IFileExistenceCheck
{
bool FileExist();
}
public class FileExistenceChecker : IFileExistenceCheck
{
private readonly string filePath;
private readonly IFileSystem fileSystem;
public FileExistenceChecker(IFileSystem fileSystem, string filePath)
{
this.fileSystem = fileSystem;
this.filePath = filePath;
}
public bool FileExist()
{
return this.fileSystem.File.Exists(this.filePath);
}
}
Run Code Online (Sandbox Code Playgroud)
然后在代码中的某个地方,我将IFIleExistenceCheck通过内核获得一个接口实例,如下所示:
public class Foo()
{
public void Bar()
{
// do something
var filePath = SomeMagicString;
var filePathArgument = new ConstructorArgument("filePath", filePath); // <- This part I do not really like
var checker = …Run Code Online (Sandbox Code Playgroud) 我是 Hibernate 新手,遇到这样的问题:虽然我配置了 Hibernate 和 MySQL 所需的所有 JARS,但当我尝试导入 SessionFactory 时,它仍然显示如下错误信息:
org.hibernate 包可以从多个模块访问:hibernate.commons.annotations、hibernate.core
有谁知道如何解决它?