我正在尝试在我的ASP.NET MVC4项目中运行RavenDb的迷你探查器。
我的Unity bootstrapper中有以下内容:
[assembly: WebActivator.PreApplicationStartMethod(typeof(Web.App.App_Start.AppStart_Unity), "Start")]
public static class AppStart_Unity
{
public static void RegisterServices(IUnityContainer container)
{
container.RegisterInstance(DocumentStoreFactory.Create(ConfigurationManager.ConnectionStrings[0].Name));
container.RegisterType<IDocumentSession>(new HierarchicalLifetimeManager(), new InjectionFactory(c => c.Resolve<IDocumentStore>().OpenSession(ConfigurationManager.ConnectionStrings[0].Name)));
}
public static void Start()
{
// Create the unity container
IUnityContainer container = new UnityContainer();
// Register services with our Unity container
RegisterServices(container);
// Tell ASP.NET MVC to use our Unity DI container
DependencyResolver.SetResolver(new UnityServiceLocator(container));
// hook up the profiler
var store = container.Resolve<IDocumentStore>();
var documentStore = store as DocumentStore;
if (documentStore != null)
{
Raven.Client.MvcIntegration.RavenProfiler.InitializeFor(documentStore);
}
}
}
在我的主人_Layout我有以下内容:
<head>
@Raven.Client.MvcIntegration.RavenProfiler.CurrentRequestSessions()
</head>
我第一次启动Web应用程序时,我可以看到分析器,没问题。
但是,任何后续页面请求和分析器都不可见。
当我查看页面源代码时,我可以看到div容器在那里,但是没有填充数据。完全没有JavaScript错误。很奇怪。呈现的HTML如下所示:
<div class="ravendb-profiler-results">
<div id="ravendb-session-container"></div>
<p></p>
<a href="#" class="ravendb-toggle ravendb-close">Close</a>
</div>
比较请求,我在第一次加载时看到了这些请求:
http://localhost:62238/ravendb/profiling?path=yepnope.js
http://localhost:62238/ravendb/profiling?path=jquery.tmpl.min.js
http://localhost:62238/ravendb/profiling?path=ravendb-profiler-scripts.js
http://localhost:62238/ravendb/profiling?path=jquery.tmpl.min.js
http://localhost:62238/ravendb/profiling?path=ravendb-profiler-scripts.js
http://localhost:62238/ravendb/profiling?path=Templates%2Ftotals.tmpl.html
http://localhost:62238/ravendb/profiling?path=Templates%2Fravendb-profiler.tmpl.html
http://localhost:62238/ravendb/profiling?path=Templates%2Fsession-template.tmpl.html
http://localhost:62238/ravendb/profiling?path=Templates%2Frequest-details.tmpl.html
http://localhost:62238/ravendb/profiling?id%5B%5D=d3ada4e4-4bc3-4a7c-bd36-64cc8017d94a
http://localhost:62238/ravendb/profiling?path=styles.css
在后续加载中,我看到以下请求:
http://localhost:62238/ravendb/profiling?path=yepnope.js
http://localhost:62238/ravendb/profiling?path=jquery.tmpl.min.js
http://localhost:62238/ravendb/profiling?path=ravendb-profiler-scripts.js
http://localhost:62238/ravendb/profiling?path=jquery.tmpl.min.js
http://localhost:62238/ravendb/profiling?path=ravendb-profiler-scripts.js
奇怪的是,我发现jquery.tmpl.min.js
和ravendb-profiler-scripts.js
的重复通话 。
ravendb-profiler-scripts.js包含以下行:
9. var load = function () {
10. if (options.id.length == 0)
11. return;
在后续加载中,options.id.length为零。然后,模板无法加载,并且不会获取结果。
第一页加载包含脚本:
<script type="text/javascript">
yepnope([{ test: window.jQuery, nope: '/ravendb/profiling?path=jquery-1.6.1.min.js' }, { test: window.jQuery && window.jQuery.fn.tmpl, nope: '/ravendb/profiling?path=jquery.tmpl.min.js' }, {load: '/ravendb/profiling?path=ravendb-profiler-scripts.js', complete: function() { jQuery(function() { RavenDBProfiler.initalize({ id:['df05238a-24a6-4a16-ad63-3b9537e9b544'], url: '/ravendb/profiling' }); }) } }]);
</script>
后续加载包含:
<script type="text/javascript">
yepnope([{ test: window.jQuery, nope: '/ravendb/profiling?path=jquery-1.6.1.min.js' }, { test: window.jQuery && window.jQuery.fn.tmpl, nope: '/ravendb/profiling?path=jquery.tmpl.min.js' }, {load: '/ravendb/profiling?path=ravendb-profiler-scripts.js', complete: function() { jQuery(function() { RavenDBProfiler.initalize({ id:[], url: '/ravendb/profiling' }); }) } }]);
</script>
请注意缺少 id 对象。
我也试过了mini-profiler,我也尝试从最新的不稳定的RavenDb客户端回滚到当前的稳定版本。似乎没有任何区别。
这是预期的行为吗?我还需要做其他事吗?我在这里是个白痴吗?
更新
我刚刚安装了Glimpse.Ravendb插件并报告:
EmbeddableDocumentStore目前不支持分析。
但是,我显然没有使用EmbeddableDocumentStore
:
public static class DocumentStoreFactory
{
public static IDocumentStore Create(string connectionStringName)
{
var documentStore = new DocumentStore { ConnectionStringName = connectionStringName };
documentStore.Initialize();
documentStore.DatabaseCommands.EnsureDatabaseExists(connectionStringName);
var catalog = new CompositionContainer(new AssemblyCatalog(typeof(Users_ByKarmaAndLocation).Assembly));
IndexCreation.CreateIndexes(catalog, documentStore.DatabaseCommands.ForDatabase(connectionStringName), documentStore.Conventions);
return documentStore;
}
}
我不确定这是不是红鲱鱼。以为我会提到它。
答案 0 :(得分:0)
问题出在我的Unity设置上。我不应该使用Unity HierarchicalLifetimeManager()
而是使用PerResolveLifetimeManager()
。重新启动应用程序后,Glimpse问题就解决了。
事后看来,我应该更加关注不同类型的LifetimeContainers并正确使用它们。
更新的Unity配置如下所示:
public static class AppStart_Unity
{
public static void RegisterServices(IUnityContainer container)
{
container.RegisterInstance(DocumentStoreFactory.Create(ConfigurationManager.ConnectionStrings[0].Name));
//container.RegisterType<IDocumentSession>(new HierarchicalLifetimeManager(), new InjectionFactory(c => c.Resolve<IDocumentStore>().OpenSession(ConfigurationManager.ConnectionStrings[0].Name)));
container.RegisterType<IDocumentSession>(new PerResolveLifetimeManager(), new InjectionFactory(c => c.Resolve<IDocumentStore>().OpenSession()));
}
public static void Start()
{
// Create the unity container
IUnityContainer container = new UnityContainer();
// Register services with our Unity container
RegisterServices(container);
// Tell ASP.NET MVC to use our Unity DI container
DependencyResolver.SetResolver(new UnityServiceLocator(container));
var store = container.Resolve<IDocumentStore>();
var documentStore = store as DocumentStore;
if (documentStore == null)
{
return;
}
RavenProfiler.InitializeFor(
documentStore,
"Email", "HashedPassword", "AkismetKey", "PasswordSalt", "UserHostAddress");
Profiler.AttachTo(documentStore);
}
}