小编Rui*_*mba的帖子

SignalR 2.0使用Ninject注入接口

我有以下简单的Hub类来列出使用注入用户服务的用户.使用NinjectSignalRDependencyResolver的启动类.非常简单的客户端脚本.

[HubName("dashboardHub")]
public class DashboardHub : Hub
{
    private readonly IUserService _users;

    public DashboardHub(IUserService users)
    {
        _users = users;
    }

    public void Initialize()
    {
        var users = _users.ListUsers();

        Clients.All.UpdateStatus(users);
    }
}
Run Code Online (Sandbox Code Playgroud)

startup.cs

  var kernel = new StandardKernel();
  var resolver = new NinjectSignalRDependencyResolver(kernel);

  var config = new HubConfiguration()
  {
        Resolver = resolver,
  };

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

NinjectSignalRDependencyResolver

public class NinjectSignalRDependencyResolver : DefaultDependencyResolver
{
    private readonly IKernel _kernel;

    public NinjectSignalRDependencyResolver(IKernel kernel)
    {
        _kernel = kernel;
    }

    public override object GetService(Type serviceType)
    {
        return …
Run Code Online (Sandbox Code Playgroud)

.net dependency-injection ninject signalr

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

无法在VSTS上恢复nuget包(包无法安装)

我正在使用Visual Studio Team Services来构建.NET解决方案.我有一项Nuget Installer任务是恢复配置如下的解决方案的包:

在此输入图像描述

Nuget.configfile有2个包源 - 一个是nuget.org(v2),另一个是自定义源(Nuget Server v2.5.40416.9020).来自nuget.org订阅源的所有包都已恢复,但自定义订阅源中的包不是,对于自定义订阅源中的每个包,都会出现如下错误消息:

无法找到包'xyz'的版本'abc'

错误:

[错误]错误:C:\ a_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.22 \node_modules \nuget-task-common\NuGet\3.3.0\NuGet.exe失败,返回码:1 [错误]软件包无法安装

这在1天或2天前工作正常.

在当地一切似乎都很好.此外,我尝试使用nuget版本3.5.0和自定义版本nuget.exe,但没有成功.

有什么建议?

continuous-integration nuget visual-studio-2013 nuget-package-restore azure-devops

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

如何在 VSTS 上配置单元测试名称/描述?

我有一个包含单元测试项目的解决方案。我正在使用 NUnit v3.10.1 和 NUnit3TestAdapter v3.10.0。

有没有办法配置测试名称在 Visual Studio Team Services (VSTS) 中的显示方式,也许显示测试类名称?目前它只显示测试名称:

VSTS 中的测试名称

很难理解哪个测试属于哪个类。在这种情况下,我至少有 2 个具有相同测试名称的测试类。

使用 Reshaper 的测试运行器运行相同的测试,很容易理解哪些测试属于哪些类:

按项目结构分组的 Resharper 单元测试

我曾尝试设置TestName的的的TestFixture属性的属性或设置Description的的测试属性,没有运气:

[TestFixture(TestName = "MemoryCacheManagerTests_TryGetItem", TestOf = typeof(MemoryCacheManager))]
public class MemoryCacheManagerTests_TryGetItem : MemoryCacheManagerTests
{
    [Test(Description = "MemoryCacheManagerTests_TryGetItem_WithInvalidCacheKey_ShouldThrowArgumentException")]
    [TestCaseSource(typeof(InvalidCacheKeyTestCases))]
    public void WithInvalidCacheKey_ShouldThrowArgumentException(string key)
    {
        // ...
    }
}
Run Code Online (Sandbox Code Playgroud)

那么如何在 VSTS 上配置测试的名称呢?

.net c# nunit unit-testing azure-devops

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

Azure Devops - 按代理池 ID 获取版本定义

我正在尝试使用 .NET 客户端库查找配置为使用特定代理池的所有版本和版本。

假设agentPoolId,我可以得到所有这样的构建定义:

// _connection is of type VssConnection
using (var buildClient = _connection.GetClient<BuildHttpClient>())
{
    List<BuildDefinitionReference> allBuilds = await buildClient.GetDefinitionsAsync(projectName, top: 1000, queryOrder: DefinitionQueryOrder.DefinitionNameAscending);
    List<BuildDefinitionReference> builds = allBuilds.Where(x => HasAgentPoolId(x, agentPoolId)).ToList();
}

private bool HasAgentPoolId(BuildDefinitionReference buildDefinition, int agentPoolId)
{
    TaskAgentPoolReference pool = buildDefinition?.Queue?.Pool;

    if (pool == null)
    {
        return false;
    }

    return pool.Id.Equals(agentPoolId);
}
Run Code Online (Sandbox Code Playgroud)

但是我找不到一种方法来查找具有一个或多个环境配置为使用特定代理的发布定义。有什么建议吗?

.net c# tfs-sdk azure-devops

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

来自 launchsettings.json 的环境变量正在测试中使用吗?

我有一个 .NET Core 构建管道,用于在 Azure DevOps 上运行一些测试。每个环境的设置都存储在配置文件中,例如:

  • appsettings.json
  • appsettings.qa.json
  • appsettings.test.json

构建是非常基础的——它包含一个dotnet restore,dotnet builddotnet test任务:

构建定义

ASPNETCORE_ENVIRONMENT环境变量设置的变量构建管道的部分:

构建变量

这些构建在包含多个构建代理(私有,非托管)的 VM 上运行。

现在是奇怪的部分 -有时构建会选择错误的设置!.

经过一些调查并添加更多日志记录后,我们意识到ASPNETCORE_ENVIRONMENTvalue 有时是Development-Selfhost,而不是QA。该值似乎来自launchsettings.json测试项目引用的项目文件:

{
  "profiles": {
    "MyProject.PublicApi": {
      "commandName": "Project",
      "launchBrowser": false,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development-Selfhost"
      },
      "applicationUrl": "http://localhost:5028/"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在ASP.NET核心使用多个环境launchSettings.json当一个应用程序与启动时使用的文件dotnet run

launchSettings.json如果可用,则读取。覆盖环境变量中的environmentVariables设置launchSettings.json

添加launchSettings.jsonto.gitignore解决了我的问题,但如果我不在 …

c# .net-core azure-devops

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

基于接口生成的表达式

收到异常 无法将类型“MySomeTypeThatImplementsISomeInterfaceAndIsPassedAs[T]ToTheClass”转换为类型“ISomeInterface”。LINQ to Entities 仅支持强制转换实体数据模型基元类型。

我的存储库看起来像

public interface IRepository<T>
{
    IQueryable<T> Get(System.Linq.Expressions.Expression<System.Func<T, bool>> Query);
}
Run Code Online (Sandbox Code Playgroud)

另外,我有服务类

public abstract class FinanceServiceBase<TAccount, TParcel, TPayment>
    where TAccount : IAccount
    where TParcel : IParcel
    where TPayment : IPayment
 {
     //...
     IRepository<TPayment> ParcelRepository {get; private set;}         

     public bool MakePayment(TPayment payment)
     {
         //...
         ParcelRepository.Get(p => p.ParcelId == 2);
         // here my exception is thrown
         // **p.ParcelId is in IParcel**
         //...
     }
 }
 //...
Run Code Online (Sandbox Code Playgroud)

有了这门课,我可以控制很多关于财务的事情,而无需为其他程序重写代码。我用 3 个泛型参数做了这个类,因为我不能使用 IRepository 因为我的存储库不能<out T>

ParcelId 是 Int32
TParcel …

c# lambda code-reuse entity-framework

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

如何在Html.TextBoxFor中使用ShortDate字符串格式

使用Entity Framework和MVC2,我有一系列日期文本框,我想以短日期格式显示模型中的数据,但我必须使用Html.TextBoxFor才能使更新代码正常工作(尝试使用HTML) .Textbox数据永远不会保存到模型中).

<%: Html.TextBoxFor(model => model.Item.Date, String.Format("{0:d}", Model.Item.Date))%>
Run Code Online (Sandbox Code Playgroud)

我已经尝试过操作字符串格式表达式,并将元数据添加到映射到Entity Framework模型类的部分类中,但是我仍然在表单渲染中填充以下文本框:

01/01/2011 00:00:00 
Run Code Online (Sandbox Code Playgroud)

而不是

01/01/2011
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc entity-framework asp.net-mvc-2

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

我可以在Entity Framework的Where方法中使用自定义委托方法吗?

Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate);
Run Code Online (Sandbox Code Playgroud)

我将参数传递给Where方法,如下所示:f => f.Id > 4.我可以传递委托方法而不是f.Id > 4吗?

.net c# delegates entity-framework

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

Entity Framework Fluent API用于映射简单的一对多关系

我有两张桌子:

  • 文件(Id,DocumentTypeId,标题,详细信息)
  • DocumentTypes(Id,Name,Description).

DocumentTypeId是引用DocumentTypes表的外键.即所有文档都可以分配一个类型.

我有两节课:

public class Document
{
    public string Id { get; set; }
    public string Title { get; set; }
    public DocumentType DocumentType { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

public class DocumentType
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我有一个配置

internal class DocumentsConfiguration : EntityTypeConfiguration<Document>
{
    public DocumentsConfiguration()
    {
        ToTable("Documents");
        HasKey(document => document.Id);
        Property(document => document.Id).HasColumnName("Id");

        HasRequired(document => document.DocumentType);//????????

        Property(document => …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework

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

dart pub在代理后面失败-是否可以手动安装软件包?

在公司网络中使用代理(至少在Windows计算机上)使用Pub dart存在一个已知问题。您甚至无法运行示例,因为它们使用pub来获取软件包。如果您是先从没有代理的网络上运行示例,则从代理后面运行它们时,它们的工作原理非常好(软件包已安装)。

我的问题是:如何手动安装软件包?

例如,我当然可以从git中获得它们,但是之后要做什么才能“安装”它们,我对Dart安装目录,用户目录和似乎必要的符号链接中的内容感到困惑。可能是我错过了一些东西,但是我没有找到任何相关的好文档。

谢谢,

F。

dart dart-pub

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