所以我有一个执行工作流程的Windows服务流程.后端在Entity Framework之上使用Repository和UnitofWork Pattern and Unity,以及从edmx生成的实体类.我不会详细介绍它,因为它不是必需的,但基本上工作流程有5个步骤.特定过程可能在任何时间点的任何阶段(按当然顺序).第一步只生成第二步的数据,它通过长时间运行的进程验证数据到另一台服务器.然后步骤生成带有该数据的pdf.对于每个阶段,我们生成一个计时器,但是它可以配置为允许为每个阶段生成多个计时器.其中就是问题所在.当我将处理器添加到特定阶段时,它会随机出现以下错误:
连接没有关闭.连接的当前状态是连接.
阅读这一点似乎很明显,这种情况正在发生,因为上下文试图从两个线程访问同一个实体.但这就是让我陷入困境的地方.我可以在此找到的所有信息表明我们应该在每个线程中使用实例上下文.据我所知,我正在做什么(见下面的代码).我没有使用单例模式或静态或任何东西所以我不确定为什么会发生这种情况或如何避免它.我在下面发布了我的代码的相关部分供您查看.
基础存储库:
public class BaseRepository
{
/// <summary>
/// Initializes a repository and registers with a <see cref="IUnitOfWork"/>
/// </summary>
/// <param name="unitOfWork"></param>
public BaseRepository(IUnitOfWork unitOfWork)
{
if (unitOfWork == null) throw new ArgumentException("unitofWork");
UnitOfWork = unitOfWork;
}
/// <summary>
/// Returns a <see cref="DbSet"/> of entities.
/// </summary>
/// <typeparam name="TEntity">Entity type the dbset needs to return.</typeparam>
/// <returns></returns>
protected virtual DbSet<TEntity> GetDbSet<TEntity>() where TEntity : class
{
return Context.Set<TEntity>();
}
/// <summary> …Run Code Online (Sandbox Code Playgroud) 只是为了澄清,我使用动态和MakeGenericType.但我不能帮助,但认为有更好的方法来做到这一点.我想要做的是使用Unity创建一个"插件"加载器.我将在发布代码时对其进行解释,以便您了解我正在做的事情.
首先,我将发布插件本身:
[RegisterAction("MyPlugin", typeof(bool), typeof(MyPlugin))]
public class MyPlugin: IStrategy<bool>
{
public IStrategyResult<bool> Execute(ISerializable info = null)
{
bool result;
try
{
// do stuff
result = true;
}
catch (Exception)
{
result = false;
}
return new StrategyResult<bool>
{
Value = result
};
}
}
Run Code Online (Sandbox Code Playgroud)
在这里要注意的事情.首先是RegisterActionAttribute:
[AttributeUsage(AttributeTargets.Class)]
public sealed class RegisterActionAttribute : Attribute
{
public StrategyAction StrategyAction { get; }
public RegisterActionAttribute(string actionName, Type targetType, Type returnType, params string[] depdencies)
{
StrategyAction = new StrategyAction
{
Name = actionName,
StrategyType …Run Code Online (Sandbox Code Playgroud) 我之前问了一个问题,所给出的答案是正确的,但是我越往下走到这个兔子洞,我就越发现; 我不认为我问的是正确的问题.
让我用最简单的术语解释一下我能...我有一个AngularJS单页面应用程序(客户端),它指向一个asp.net webapi(OWIN)站点(资源服务器?)和一个单独的asp.net "授权/验证"服务器.
auth服务器将为多个应用程序提供身份验证和授权.我需要能够在资源服务器中使用Authorize属性,以及从angular获取令牌.我还需要对所有内容使用Windows身份验证(集成),没有用户名或密码.声明信息存储在数据库中,需要添加到令牌中.
我使用带有JwtBearerToken的openiddict和'密码流?'在asp.net核心中完成了一个SSO样式声明授权实现.并且想尝试做类似的事情(令牌等).我基本了解了我以前的工作方式是如何工作的,但是我完全不知道如何让JWT使用Windows Auth.我之前的问题的答案提供了一些很好的建议,但我很难看到这种情况如何适用.
目前我一直试图让IdentityServer3使用WindowsAuthentication扩展来实现这一点,主要是从样本中提取.但我真的很难将它与客户联系在一起并实际上得到了一些工作.当前的客户端和服务器代码在下面,请注意,我真的不知道这是否接近正确的解决方案.
客户:
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Passive,
AuthenticationType = "windows",
Authority = "http://localhost:21989",
ClientId = "mvc.owin.implicit",
ClientSecret = "api-secret",
RequiredScopes = new[] { "api" }
});
Run Code Online (Sandbox Code Playgroud)
AuthServer:
app.Map("/windows", ConfigureWindowsTokenProvider);
app.Use(async (context, next) =>
{
if (context.Request.Uri.AbsolutePath.EndsWith("/token", StringComparison.OrdinalIgnoreCase))
{
if (context.Authentication.User == null ||
!context.Authentication.User.Identity.IsAuthenticated)
{
context.Response.StatusCode = 401;
return;
}
}
await next();
});
var factory = new IdentityServerServiceFactory()
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get());
var options = new IdentityServerOptions
{
SigningCertificate = …Run Code Online (Sandbox Code Playgroud) 我正在努力将ASP.NET项目迁移到RC2.我正在使用AutoFac来尝试枚举实现AutoMapper Profile基类的类来设置我的所有映射配置文件,而无需显式调用它们.以前在旧版本的ASP.NET中(甚至在RC1中)我能够使用以下代码:
public class AutoMapperModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterAssemblyTypes().AssignableTo(typeof(Profile)).As<Profile>();
builder.Register(context =>
{
var profiles =
AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(IoC.GetLoadableTypes)
.Where(t => t != typeof(Profile) && t.Name != "NamedProfile" && typeof(Profile).IsAssignableFrom(t));
var config = new MapperConfiguration(cfg =>
{
foreach (var profile in profiles)
{
cfg.AddProfile((Profile)Activator.CreateInstance(profile));
}
});
return config;
})
.AsSelf()
.As<IConfigurationProvider>()
.SingleInstance();
builder.Register(c => c.Resolve<MapperConfiguration>().CreateMapper(c.Resolve)).As<IMapper>().InstancePerLifetimeScope();
builder.RegisterType<MappingEngine>().As<IMappingEngine>();
}
}
Run Code Online (Sandbox Code Playgroud)
这非常有效,直到我尝试使用新的netcoreapp1.0框架将我的项目转换为RC2,除了现在我在AppDomain上收到设计时错误,声明"AppDomain在当前上下文中不存在".我已经看到了一些关于使用ILibraryManager或DependencyContext来做到这一点的建议,但我无法弄清楚如何使其中任何一个工作.有什么建议?
我正在尝试在Visual Studio 2015项目中设置新的网站环境.我把一切都搞定了; NPM,Bower,Gulp.它正在生成和缩小我的所有js和css,除了Modernizr,我似乎被困在了.
我将modernizr添加到我的bower.json文件中,VS创建了bower_components文件夹.但是目录中没有modernizr.js.我在这里发现另一篇文章建议做一个"凉亭缓存",但这似乎根本没有改善情况.
有任何想法吗?
我正在使用MVC 3和Razor,尝试将表单从telerik窗口(telerik.window.create)发送回控制器,该窗口加载部分视图.我不知道怎么发布这个如此生病只是按照执行的顺序发布代码并解释它我去.
首先点击一个锚点,然后点击onClick:
function showScheduleWindow(action, configId) {
var onCloseAjaxWindow = function () { var grid = $("#SubscriptionGrid").data("tGrid"); if (grid) { grid.rebind(); } };
CreateAjaxWindow("Create Schedule", true, false, 420, 305, "/FiscalSchedule/" + action + "/" + configId, onCloseAjaxWindow);
}
Run Code Online (Sandbox Code Playgroud)
和CrateAjaxWindow方法:
function CreateAjaxWindow(title, modal, rezible, width, height, url, fOnClose) {
var lookupWindow = $.telerik.window.create({
title: title,
modal: modal,
rezible: rezible,
width: width,
height: height,
onClose: function (e) {
e.preventDefault();
lookupWindow.data('tWindow').destroy();
fOnClose();
}
});
lookupWindow.data('tWindow').ajaxRequest(url);
lookupWindow.data('tWindow').center().open();
}
Run Code Online (Sandbox Code Playgroud)
这是正在加载的局部视图:
@model WTC.StatementAutomation.Web.Models.FiscalScheduleViewModel
@using WTC.StatementAutomation.Model
@using …Run Code Online (Sandbox Code Playgroud) 我正在尝试移植一些使用 OwinContext.Environment 的 Owin 中间件。我知道我可以使用 AspNetCore.Owin nuget 包支持旧的 Owin 内容,但由于 owin 现在已集成到 ASP.NET Core 中,我想全部更新。
我知道环境属性只是一个 IDictionary,但我不确定的是,就上下文、范围、生命周期等而言,该对象有什么特殊之处(如果有的话)。查看源代码,它看起来像它只不过是 OwinContext 类上带有私有 setter 的公共虚拟变量。在 .net core 中实现类似的功能显然不需要旧 Owin 上下文使用的所有其他键值对,因为它不再存在了。因此,复制该功能似乎相对容易。
也就是说,我只是想弄清楚 .net core 中是否还有其他东西可以提供类似的功能,或者我是否需要推出自己的功能?