小编Gok*_*ath的帖子

SignalR vs setTimeout

从服务器获取一些资源后,我的MVC视图页面的一部分每30秒刷新一次.我一直在使用setTimeOut触发javascript方法异步从服务器获取数据,将其与旧数据进行比较,如果已更改,则更新div标签.现在,我正在考虑在global.asax类中创建一个计时器,在application_start事件中启动它,在timer elapsed事件中,获取数据,并且只有在数据发生变化时才使用SignalR将它发送给所有客户端.

在这里使用SignalR而不是setTimeOut会有什么优势吗?

asp.net-mvc signalr

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

实体框架子查询

如何在EF中编写这样的子查询?

select * from table1 where col1 in (select col1 from table2 where col2 = 'xyz')
Run Code Online (Sandbox Code Playgroud)

要么

select * from table1 where col1 not in (select col1 from table2 where col2 = 'xyz')
Run Code Online (Sandbox Code Playgroud)

我试过这样的东西

from t1 in table1
where (from t2 in table2 where col2 = 'xyz' select t2.col1).Contains(t1.col1)
select t1
Run Code Online (Sandbox Code Playgroud)

from t1 in table1
where !(from t2 in table2 where col2 = 'xyz' select t2.col1).Contains(t1.col1)
select t1
Run Code Online (Sandbox Code Playgroud)

这些查询工作正常LinqPad或Linq到Sql

.net entity-framework subquery

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

OWIN中间件+ Web API +简单注入器

我目前正在使用WebApiRequestLifestyle具有默认的范围生活方式.我想在OWIN中间件和其中一个API控制器中注入一个服务,服务的范围应该仍然是WebAPI,即对于整个请求,应该只有一个服务实例.

public class TestMiddleware : OwinMiddleware
{
    private readonly ITestService _testService;

    public TestMiddleware(OwinMiddleware next, ITestService testService) : base(next)
    {
        _testService = testService;
    }

    public override async Task Invoke(IOwinContext context)
    {
        var test = _testService.DoSomething();
        await Next.Invoke(context);
    }
}

public class ValuesController : ApiController
{
    private readonly ITestService _testService;

    public ValuesController(ITestService testService)
    {
        _testService = testService;
    }
}
Run Code Online (Sandbox Code Playgroud)

整个请求的ITestService实例应该相同.我该如何注册中间件?

这就是我现在这样做的方式:

     using (container.BeginExecutionContextScope())
        {
            var testService = container.GetInstance<ITestService>();
            app.Use<TestMiddleware>(testService);
        }
Run Code Online (Sandbox Code Playgroud)

这种方法的问题是 - 在注册期间为中间件创建一个ITestService实例并永久保留(如单例),并且对于每个webapi请求,都会在控制器之间创建和共享新实例(webapi范围)

请不要指出这些问题 - WebApi + Simple Injector + OWIN

使用Simple …

c# dependency-injection simple-injector asp.net-web-api owin

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