3

我正在尝试在我的 ASP.NET MVC4 项目中运行 RavenDb 的迷你分析器。

我的 Unity 引导程序中有以下内容:

[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>

比较请求,我在第一次加载时看到了这些请求:

  1. http://localhost:62238/ravendb/profiling?path=yepnope.js
  2. http://localhost:62238/ravendb/profiling?path=jquery.tmpl.min.js
  3. http://localhost:62238/ravendb/profiling?path=ravendb-profiler-scripts.js
  4. http://localhost:62238/ravendb/profiling?path=jquery.tmpl.min.js
  5. http://localhost:62238/ravendb/profiling?path=ravendb-profiler-scripts.js
  6. http://localhost:62238/ravendb/profiling?path=Templates%2Ftotals.tmpl.html
  7. http://localhost:62238/ravendb/profiling?path=Templates%2Fravendb-profiler.tmpl.html
  8. http://localhost:62238/ravendb/profiling?path=Templates%2Fsession-template.tmpl.html
  9. http://localhost:62238/ravendb/profiling?path=Templates%2Frequest-details.tmpl.html
  10. http://localhost:62238/ravendb/profiling?id%5B%5D=d3ada4e4-4bc3-4a7c-bd36-64cc8017d94a
  11. http://localhost:62238/ravendb/profiling?path=styles.css

在随后的加载中,我看到以下请求:

  1. http://localhost:62238/ravendb/profiling?path=yepnope.js
  2. http://localhost:62238/ravendb/profiling?path=jquery.tmpl.min.js
  3. http://localhost:62238/ravendb/profiling?path=ravendb-profiler-scripts.js
  4. http://localhost:62238/ravendb/profiling?path=jquery.tmpl.min.js
  5. http://localhost:62238/ravendb/profiling?path=ravendb-profiler-scripts.js

奇怪的是,我在这两种情况下都看到重复调用jquery.tmpl.min.jsravendb-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对象。

我还尝试了迷你分析器,还尝试从最新的不稳定 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;
    }
}

我不确定这是否是红鲱鱼。以为我会提到它。

4

1 回答 1

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);
    }
}
于 2012-09-10T10:44:28.380 回答