Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:04:42+00:00 2026-06-04T13:04:42+00:00

In my project, I have the following PageCache entity, which is being stored in

  • 0

In my project, I have the following PageCache entity, which is being stored in RavenDB:

public class PageCache
{
    private readonly IHtmlDocumentHelper htmlDocumentHelper;

    public string Id { get; set; }
    public string Url { get; set; }

    public PageCache(IHtmlDocumentHelper htmlDocumentHelper, string url)
    {
        this.htmlDocumentHelper = htmlDocumentHelper;
        this.Url = url;
    }
}

I am using Castle Windsor to inject the IHtmlDocumentHelper implementation at runtime. This member is used in methods defined inside the PageCache class, which I stripped from the above snippet for the sake of simplicity.

When I create a PageCache object using the constructor, everything works fine. But elsewhere in my code, I load PageCache objects back from RavenDB:

public PageCache GetByUrl(string url)
{
    using (var session = documentStore.OpenSession())
    {
        return session.Query<PageCache>()
                      .Where(x => x.Url == url)
                      .FirstOrDefault();
    }
}

My issue is that the objects I get back from RavenDB don’t have the htmlDocumentHelper member set, rendering the PageCache methods that depend on it unuseable.

In other words: when I load objects back from documents stored in RavenDB, it won’t use my constructor to build the objects, thus not initializing the private members through constructor injection.

Am I doing something wrong here? How would you solve such an issue?


I ended up using the solution proposed by Ayende below. The circular dependency issue I mentioned in the comments only appeared when I registered the DocumentStore in Windsor with UsingFactoryMethod(). The issue strangely disappeared when I used Windsor’s DependsOn() and OnCreate() to configure and initialize the DocumentStore directly inside the Register().

My container is now being initialized as follows:

WindsorContainer container = new WindsorContainer();

container.Register(
    // Register other classes, such as repositories and services.
    // Stripped for the sake of clarity.
    // ...

    // Register the CustomJsonConverter:
    Component.For<CustomJsonConverter>().ImplementedBy<CustomJsonConverter>(),

    // The following approach resulted in an exception related to the circular
    // dependencies issue:
    Component.For<IDocumentStore>().UsingFactoryMethod(() =>
        Application.InitializeDatabase(container.Resolve<CustomJsonConverter>()))

    // Oddly enough, the following approach worked just fine:
    Component.For<IDocumentStore>().ImplementedBy<DocumentStore>()
        .DependsOn(new { Url = @"http://localhost:8080" })
        .OnCreate(new Action<IDocumentStore>(store =>
            store.Conventions.CustomizeJsonSerializer = serializer =>
                serializer.Converters.Add(container.Resolve<CustomJsonConverter>())))
        .OnCreate(new Action<IDocumentStore>(store =>
            store.Initialize()))
        .OnDestroy(new Action<IDocumentStore>(store =>
            store.Dispose()))
    );

Although it seems to be working fine, I feel odd having to call container.Resolve<CustomJsonConverter>() from inside the container.Register() method.

Is this a legal approach to register the dependencies?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:04:44+00:00Added an answer on June 4, 2026 at 1:04 pm

    Christian,
    We can’t use your ctor, we don’t know what to put in there.

    Instead, you can use this technique to tell RavenDB how to create your objects:
    http://james.newtonking.com/projects/json/help/CustomCreationConverter.html

    Then you can wire this in using documentStore.Conventison.CustomizeSerializer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Project model: public class Project { [Key] public int ProjectID
In an MVC project I have the following classes: public abstract class Browse<T> where
In my project I have the following three interfaces, which are implemented by classes
I have following Enum in my project public enum CameraAccessMethod { Manual = 0,
I have a project in which i have the following files main.wxs - directory
I am using ups service for my project,I have the following code which is
In my Rails 3 project I have the following code for My controller: class
I have the following solution structure: Portal.DataAccess -> Class library project with methods against
I have the following interfaces defined in a base library project: public interface IWorkContext
I have the following situation. I have a project model which have many meetings,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.