小编Pau*_*unt的帖子

使用ASP.NET Web API 2.1配置依赖项注入

我正在创建一个ASP.NET Web API 2.1站点,因为我想将依赖项直接注入控制器,所以我创建了自己的IDependencyResolver实现,以便StructureMap为我处理.

public class StructureMapDependencyResolver : IDependencyResolver
{
    public IDependencyScope BeginScope()
    {
        return this;
    }

    public object GetService(Type serviceType)
    {
        return ObjectFactory.GetInstance(serviceType);
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {            
        return ObjectFactory.GetAllInstances(serviceType).Cast<object>();
    }

    public void Dispose()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

然后,我通过将此行添加到Global.asax中的Application_Start方法,告诉Web API使用此类

GlobalConfiguration.Configuration.DependencyResolver = new StructureMapDependencyResolver();
Run Code Online (Sandbox Code Playgroud)

编译,但当我尝试访问浏览器中的任何API方法时,我得到了这样的错误

No Default Instance defined for PluginFamily System.Web.Http.Hosting.IHostBufferPolicySelector, System.Web.Http
Run Code Online (Sandbox Code Playgroud)

当我在StructureMap配置中添加一行时,那个相对容易解决

this.For<IHostBufferPolicySelector>().Use<WebHostBufferPolicySelector>();
Run Code Online (Sandbox Code Playgroud)

然而,我得到了其他System.Web.Http类的其他类似错误,虽然我可以解决其中的一些,但我仍然坚持如何处理其中的3个,即ITraceManager,IExceptionHandler和IContentNegotiator.

问题是TraceManager似乎是ITraceManager的默认实现,是一个内部类,所以我不能在我的StructureMap配置中引用它.

那么我是以完全错误的方式进行此操作还是有其他方法来注入这些内部类?

structuremap asp.net dependency-injection asp.net-web-api

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

如何在dotnet核心测试项目中使用用户机密

我想将集成测试的数据库连接字符串存储为用户密码.我的project.json看起来像这样:

{
  ...

  "dependencies": {
    ...
    "Microsoft.Extensions.Configuration.UserSecrets": "1.1.0"        
  },

  "tools": {
    "Microsoft.Extensions.SecretManager.Tools": "1.1.0-preview4-final"
  },

  "userSecretsId": "dc5b4f9c-8b0e-4b99-9813-c86ce80c39e6"
}
Run Code Online (Sandbox Code Playgroud)

我已将以下内容添加到我的测试类的构造函数中:

IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .AddUserSecrets();
Run Code Online (Sandbox Code Playgroud)

但是,当我运行测试时,当它到达该行时抛出以下异常:

An exception of type 'System.InvalidOperationException' occurred in Microsoft.Extensions.Configuration.UserSecrets.dll but was not handled in user code

Additional information: Could not find 'UserSecretsIdAttribute' on assembly 'dotnet-test-nunit, Version=3.4.0.0, Culture=neutral, PublicKeyToken=null'.
Run Code Online (Sandbox Code Playgroud)

我错过了什么或是我想要不支持的东西吗?

configuration unit-testing app-secret .net-core

9
推荐指数
3
解决办法
3519
查看次数

并行运行2个TeamCity代理的自动化测试

我们将TeamCity与MsTest一起使用来管理和运行自动化测试套件,以便对WPF应用程序进行前端测试.

目前,测试套件运行在一个专用的测试代理(安装了TC)上,我现在处于一个需要大幅缩短运行时间的阶段.我想通过添加另一个测试代理来并行运行测试来做到这一点.

我的测试场景很大,所以我将它们分成大约4个按顺序运行的Specflow功能文件.所有这些测试场景也按其功能区域进行分类.

首先: 是否可以将TeamCity配置为让一个测试代理管理要在每个测试代理上运行的测试的发送?然后在最后整理所有结果!

其次: 还要将分类测试保持在一起,需要按顺序运行?

teamcity

6
推荐指数
1
解决办法
728
查看次数

如何在 Azure Web 应用安装存储中指定带点的安装路径

我正在使用 Docker Compose 选项构建一个 Azure Web 应用程序来设置 WordPress 站点。我有一个 SQL 脚本来初始化 MySQL 数据库,该数据库需要位于目录中/docker-entrypoint-initdb.d/。我已将脚本上传到 Azure 存储容器,但当我尝试将路径安装添加到设置为的 Web 应用程序时,Mount path出现/docker-entrypoint-initdb.d/错误The parameter 'AzureStoragePropertyDictionary' has an invalid value. Details: Mount path contains invalid characters. Please review documentation for a list of valid mount path characters。更改为Mount path/docker-entrypoint-initdbd/不带点)允许保存路径挂载,但当然,应用程序启动时不会运行脚本。

这是我的 docker-compose.yml

version: '3.7'

services:   db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpressuser
      MYSQL_PASSWORD: wordpresspassword
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db_data:/var/lib/mysql
      - InitDb:/docker-entrypoint-initdb.d

  wordpress:
    depends_on: …
Run Code Online (Sandbox Code Playgroud)

mysql wordpress azure docker-compose

6
推荐指数
1
解决办法
1302
查看次数

如何在Swift中更改UISegmentedControl的选定段tintColor

我想在Swift 3中更改UISegmentedControl所选段的tintColor。我在Objective-c中搜索了很多答案。
这是我的代码:

class ViewController:UIViewController{

var segment:UISegmentedControl

override func viewDidLoad() {
super.viewDidLoad()

segment.insertSegment(withTitle: "AAA", at: 0, animated: true)
segment.insertSegment(withTitle: "BBB", at: 1, animated: true)
segment.insertSegment(withTitle: "CCC", at: 2, animated: true)

segment.addTarget(self, action: #selector(changeValue), for: .valueChanged)
segment.selectedSegmentIndex = 0

view.addSubview(segment)

}
  func changeValue(sender:AnyObject) {

  //I don't know how to do that change color when segment selected
  // 

}

}
Run Code Online (Sandbox Code Playgroud)

谢谢!

iphone uisegmentedcontrol ios swift

5
推荐指数
3
解决办法
8792
查看次数

修复从 C# Azure Function 引用 System.Data.SqlClient 时出现的 PlatformNotSupportedException

netstandard2.0我正在使用Windows 10 环境中的目标框架在 C# 中创建 Azure 函数。该函数调用另一个类库中的方法,并且该方法创建 SqlConnection 的实例。当我运行该函数时,出现以下异常:

Microsoft.Azure.WebJobs.Host.FunctionInitationException :执行函数时出现异常:Functions.RefreshImages ---> System.Reflection.TargetInitationException :调用目标已引发异常。---> System.PlatformNotSupportedException :此平台不支持 System.Data.SqlClient。在System.Data.SqlClient.SqlConnection..ctor(String connectionString)......

显然 Windows 支持 SqlConnection,所以我认为这里还发生了其他事情。

c# system.data azure-functions .net-standard

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

modIrewrite用于codeIgniter

有没有人在互联网和网络发展的历史中,能够摆脱codeIgniter中的mod_rewrite的"index.php".

我已经尝试了几天,似乎没有任何工作.

codeigniter

0
推荐指数
1
解决办法
8931
查看次数