所以我只想制作我的服务层async.
我有一个新服务ProjectManagement,我希望它的GetProjects方法是异步的.
public Task<string> GetProjectsAsync()
{
var json = JsonConvert.SerializeObject(_repository.All<Projects>());
return json;
}
Run Code Online (Sandbox Code Playgroud)
我知道这种方法不起作用,显然是因为我返回一个字符串,而不是一个字符串Task<string>.那么我如何使用Task.Run()运行此方法并返回结果?
我看过这个文档,我对如何使用它有点困惑?
我希望能够在我的控制器中执行的操作是:
var jsonData = await _projectManagement.GetProjectsAsync();
Run Code Online (Sandbox Code Playgroud) 所以我有这门课:
public class MappingBootstrap : IMappingBootstrap
{
public virtual async Task Map()
{
// Order is very important
await this.mapper1.Map();
await this.mapper2.Map();
await this.mapper3.Map();
await this.mapper4.Map();
}
}
Run Code Online (Sandbox Code Playgroud)
我有Autofac拦截器:
public class LoggingInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
var methodReference = Guid.NewGuid();
Console.WriteLine($"Calling {invocation?.Method?.DeclaringType?.Name}.{invocation?.Method?.Name} : {methodReference}");
var startNew = Stopwatch.StartNew();
invocation?.Proceed();
startNew.Stop();
Console.WriteLine($"{methodReference} : Done, time taken: {startNew.ElapsedMilliseconds}ms");
}
}
Run Code Online (Sandbox Code Playgroud)
这会产生输出:
调用IMapperBootstrap.Map:54425559-71fe-4f23-ab47-d0f3371ec819
调用IMapper1.Map:51babb34-fa83-42ed-84e7-a1e979528116
51babb34-fa83-42ed-84e7-a1e979528116:完成,所用时间:219ms
54425559-71fe-4f23- ab47-d0f3371ec819:完成,所用时间:221ms
呼叫IMapper2.Map:41c812a2-d82d-48f6-9b8d-139b52eb28e3
41c812a2-d82d-48f6-9b8d-139b52eb28e3:完成,所用时间:9ms
呼叫IMapper3.Map:c91bed04-8f86-47d3 -a35a-417e354c2c5f
c91bed04-8f86-47d3-a35a-417e354c2c5f:完成,所需时间:994ms
调用IMapper4.Map:035cad27-1ba8-4bd1-b85f-396f64998d97
035cad27-1ba8-4bd1-b85f-396f64998d97:完成,所用时间:18ms
正如您所看到的,MappingBoostrap.Map完成后的第一个Mapper1.Map而不是我期望的所有功能完成后的结束. …
我有
G---H---I---J Develop
/
A---B---C---D---E---F Master
Run Code Online (Sandbox Code Playgroud)
我想与master一起rebase Develop,所以:
G---H---I---J Develop
/
A---B---C---D---E---F Master
Run Code Online (Sandbox Code Playgroud)
所以如果我这样做git checkout develop & git rebase master
但是,它会执行变基操作,在每次提交时发现合并冲突,它将停止。
我很高兴能从开发中获取所有内容并用它覆盖。开发方面发生了巨大的变化,但每次提交都会构建并通过所有测试,因此我可以假设,如果我只是覆盖 master 中的所有内容,应该没问题。
那么我该怎么说git rebase master --choose develop side
我有:
public ActionResult Create(Guid appId)
{
var vm = new CreateViewModel(appId);
return View(vm);
}
[HttpPost]
public ActionResult Create(CreateViewModel vm)
{
// this does some stuff
}
Run Code Online (Sandbox Code Playgroud)
现在,在视图中我使用它来创建表单:
@using(Html.BeginForm())
{
}
Run Code Online (Sandbox Code Playgroud)
标准.
但是,它会产生错误的HTML:
<form action="/SomeController/Create?appId=414FDS-45F2SF-TEF234">
Run Code Online (Sandbox Code Playgroud)
这不是我想要的回帖,我不想要appId什么.只是Create
你怎么解决这个问题?
这两个实例之间是否存在差异?它存在的区别是什么?
第一:
function MyClass() {
var vm = this;
vm.initialise = function () { console.log('initialised'); }
return vm; //<-- here
}
Run Code Online (Sandbox Code Playgroud)
第二:
function MyClass() {
var vm = this;
vm.initialise = function () { console.log('initialised'); }
//<-- here
}
Run Code Online (Sandbox Code Playgroud)
用法:
var newClass = new MyClass();
Run Code Online (Sandbox Code Playgroud) 所以文档总是使用任意日期作为要检查的值。
如果我有一个具有以下属性的对象:
DateTime DueDate
DateTime NotRequired
Run Code Online (Sandbox Code Playgroud)
我该如何做这样的事情:
{
"range" : {
"NotRequired" : {
"gt" : "DueDate"
}
}
}
Run Code Online (Sandbox Code Playgroud)
如此有效地给你简单的查询让我所有实体在哪里NotRequired > DueDate?
c# ×3
asp.net-mvc ×2
.net ×1
asp.net ×1
async-await ×1
asynchronous ×1
autofac ×1
git ×1
git-rebase ×1
html ×1
interception ×1
javascript ×1