有关记录ServiceStack基础Web服务的选项有哪些,我不是在谈论单行字符串.
我希望能够详细记录(可能很长),返回类型,可能的HTTP响应,添加详细示例等.
在ServiceStack中是否有任何支持(我找不到它)?如果没有,有人以其他方式解决了这个问题.
让我们考虑一个接口中的方法:
public Interface IA {
T[] Get<T>() where T : IB;
}
Run Code Online (Sandbox Code Playgroud)
在另一个地方,我想为编译时已知的n 种类型调用此方法 n 次。下面的代码说明了我的意图。
foreach(Type t in new Type[] { typeof(X), typeof(Y), typeof(Z) })
{
InterfaceXYZImplement[] arr = c.Resolve<IA>().Get<t>();
//...more here
}
Run Code Online (Sandbox Code Playgroud)
现在,foreach循环显然使类型成为运行时值,因此我必须使用MakeGenericMethod.
有没有办法编写代码,让我可以为X,Y和执行代码Z,但只调用一次编写的方法?
将代码包装在方法中只会将问题向上移动(这是部分解决方案,但不是最终解决方案,呵呵)。
我正在尝试在LINQ-TO-SQL中创建以下查询。
select count(*), sum( o.CostInCents ) from Orders o
where Flag = true;
Run Code Online (Sandbox Code Playgroud)
我想出了以下LINQ查询:
var q = db.Orders
.Where(o => o.Flag )
var result = q
.GroupBy(o => 1)
.Select(g => new MyDTO
{
NoOfOrders = g.Count(),
TotalInCents = g.Sum(o => o.CostInCents )
})
.SingleOrDefaultAsync();
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
是.GroupBy(o => 1)即使OK?
另一个选择是执行两个查询,如下所示。
var q = db.Orders
.Where(o => o.Flag );
//No groupBy
var result2 = new MyDTO
{
NoOfCostedOrders = q.Count(),//hit the db
TotalInCents = q.Sum(o => o.CostInCents )//hit the …Run Code Online (Sandbox Code Playgroud) 我正在使用 Visual Studio Code 来查看 Git 差异。但该差异比 Visual Studio 2017 差异更难阅读。Visual Studio Code 中是否可以只有一种颜色?
Visual Studio 2017 diff(易于阅读):
Visual Studio Code diff(几乎无法阅读):
Microsoft在使用 IHostedService 和 BackgroundService 类在微服务IHostedService中实现后台任务的永久/连续示例使用while+ Task.Delay'pattern'。这用代码片段说明,简化版本就在下面。
public class GracePeriodManagerService : BackgroundService
(...)
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
//Do work
await Task.Delay(timeSpan, stoppingToken);
}
}
Run Code Online (Sandbox Code Playgroud)
这种模式受到缓慢转变的影响 - 工作每timeSpan+完成一次how_long_work_took。即使在how_long_work_took一段时间内非常小,它也会加起来。
我想避免timeSpan根据work花费的时间进行计算。
运行每个fixed_amount_of_time的稳健解决方案是什么?.
大声思考:如果我使用任务调度程序库,比如HangFire,在里面ExecuteAsync使用IHostedService/BackgroundService甚至更有意义吗?
奖励是能够在某个时间点(例如午夜)运行任务
我期待在BackgroundService从与IHostedService和BackgroundService类微服务实现后台任务
我要转换为从BackgroundService实现的继承的类IDisposable。
由于Dispose(bool disposing)没有被暴露,BackgroundService我无法调用base.Dispose(disposing);我的服务的Dispose(bool disposing).
是从BackgroundService清除中继承的类StopAsync(或在 中具有清除代码ExecuteAsync)的想法吗?
让我们想象一下,我有一个StringBuilder,我不能重构它来使用流.我想将我的内容写入StrinBuilder文件,但我不想在内存中制作额外的内容副本,即我不想打电话ToString().
我可以在不在内存中制作额外副本的情况下获取内容吗?
我相信在版本2 ToString()之前可以通过使用写入时复制来避免复制,但这不再是这种情况.
我只是想知道......为什么C#不允许多个返回值?
目前,我们表达了通过返回类或使用返回多个值的意图out- 如下所示.
static void Check(MyTask task )
{
if (GoodReasonsNotTo(task))
{
throw new ApplicationException("There are good reasons not to do this.");
}
}
public static int UglyDo( MyTask task, out string response )
{
Check(task);
//...
response = "Done";
return 7;
}
static void Main(string[] args)
{
var task = new MyTask("Add multiple return values");
string response;
var err = UglyDo(task, out reponse));
}
Run Code Online (Sandbox Code Playgroud)
上面的代码可以用不同的方式表达:
static void Check(MyTask task )
{
if (GoodReasonsNotTo(task))
{
throw new ApplicationException("There …Run Code Online (Sandbox Code Playgroud) 我有一个使用NHibernate的项目,我有一个自定义方言:
using System;
using System.Collections.Generic;
using System.Web;
public class NHibernateMySQL5InnoDBDialect : NHibernate.Dialect.MySQL5Dialect
{
public override String TableTypeString { get { return " ENGINE=InnoDB DEFAULT CHARSET=utf8"; } }
}
Run Code Online (Sandbox Code Playgroud)
我有这个类的单独程序集:Assembly1.Assembly1内置于NHibernate.dll所在的目录中.
在我的cfg文件中,我添加了:
<property name="dialect">Assembly1.NHibernateMySQL5InnoDBDialect</property>
Run Code Online (Sandbox Code Playgroud)
当我运行我的应用程序时,我收到以下错误:
NHibernate.MappingException: Could not compile the mapping document: XXX.hbm.xml ---> NHibernate.HibernateException: Could not instantiate dialect class Assembly1.NHibernateMySQL5InnoDBDialect ---> System.TypeLoadException: Could not load type Assembly1.NHibernateMySQL5InnoDBDialect. Possible cause: no assembly name specified.
at NHibernate.Util.ReflectHelper.TypeFromAssembly (NHibernate.Util.AssemblyQualifiedTypeName name, Boolean throwOnError) [0x00000] in :0
我确信有一个明显的解释,但我现在卡住了 - 你能帮帮忙吗?
关心Tymek
我创建了一个 C# .Net Standard 库,它引用了两个 Windows SDK 库。
参考文献是
C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmdC:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd这适用于我的本地开发机器。
VS Team Services 构建首先显示以下警告:
2018-06-13T01:17:22.3393846Z ##[warning]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows.Foundation.FoundationContract". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
后来它失败并出现以下错误:
Error CS0246: The type or namespace name 'Windows' could not be found (are you missing a …
c# ×7
.net ×1
.net-core ×1
azure ×1
azure-devops ×1
diff ×1
generics ×1
git ×1
idisposable ×1
linq ×1
linq-to-sql ×1
mysql ×1
nhibernate ×1
rest ×1
scheduling ×1
servicestack ×1
web-services ×1
winapi ×1
winmd ×1