我需要一种方法来存储每个请求的日志对象.使用HttpContext,我会将其添加到项目Dictionary中.如果我能帮助它,我不想把HttpContext带进去.下面的代码是我为Unity LifeTimeManager提出的建议,它将在OwinContext的Environment属性中存储对象,我可以使用我的Owin中间件访问它.
public class OwinContextLifetimeManager : LifetimeManager
{
private string key = (new Guid()).ToString();
private IDictionary<string, object> environment;
public OwinContextLifetimeManager(IDictionary<string, object> environment)
{
this.environment = environment;
}
public override object GetValue()
{
if (environment != null && environment.ContainsKey(key))
return environment[key];
else
return null;
}
public override void RemoveValue()
{
if (environment != null)
environment.Remove(key);
}
public override void SetValue(object newValue)
{
if (environment != null)
environment[key] = newValue;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我可以从我的中间件中使用它:
container.RegisterType<IRequestLog, RequestLog>(new OwinContextLifetimeManager(environment));
Run Code Online (Sandbox Code Playgroud)
在我看来,我可以选择我想要的任何键,除了那些已经由Owin保留的键.有什么理由我不应该为此目的使用OwinContext.Environment吗?MSDN文档对此的最佳实践含糊不清.
Darrel Miller在这里的回答:当使用OWIN自我主机时,我应该如何存储每个请求数据ASP.NET Web API …
设置:
我有一个使用许多JavaScript文件的大型SPA应用程序,这些文件使用Visual Studio 2013中的Web Essentials捆绑捆绑在一起.然后,我在我的HTML页面上包含Web Essentials生成的缩小的js文件.此应用程序不使用ASP.NET
问题:
我希望能够分发HTML页面,其中包含为生产引用的单个缩小脚本,但是用于开发的单个未明确脚本.
原因:
即使使用地图文件,缩小的脚本也很难调试.变量和参数名称已缩小,因此调试器与源不匹配.此外,由于所有内容都在一个文件中,因此很难查看开发.
当前解决方案
我有一个咕噜咕噜的任务进入我的html文件并修改它,以便<script>替换标签.这与我添加到页面的每个文件一起增长.
Web Essentials是否提供了比我目前正在做的更好的解决方案,我可能会忽略它?
javascript visual-studio bundling-and-minification web-essentials