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

  • SEARCH
  • Home
  • 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 121163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:55:35+00:00 2026-05-11T03:55:35+00:00

I am using windsor castle as my IoC container, and has run in to

  • 0

I am using windsor castle as my IoC container, and has run in to a bit of a problem. This is best explained in code, so I´ll give it a try. I have a factory class, that should provide me with implementations of a certain interface:

public interface IObjectCreatorFactory {     IObjectCreator GetObjectCreator(Type objectType); } public interface IObjectCreator {     T CreateObject<T>(IDataRow data);     bool SupportsType(Type type); } 

Implementation of the factory class could look like this, though I am not sure this is the way to go: public interface ObjectCreatorFactory:IObjectCreatorFactory { IEnumerable specificCreators; IObjectCreator defaultCreator;

    public ObjectCreatorFactory(IEnumerable<IObjectCreator> specificCreators, IObjectCreator defaultCreator)     {         this.specificCreators= specificCreators;         this.defaultCreator= defaultCreator;     }     public IObjectCreator GetObjectCreator(Type objectType)     {         foreach (IObjectCreator creator in specificCreators)         {             if (creator.SupportsType(objectType))             {                 return creator;             }         }         return defaultCreator;     } } 

Now this would work out ok, but if I want my IObjectCreator instance to create child objects using a specific IObjectCreator, i would like to call ObjectCreatorFactory, and this obviously results in a circular reference:

public void SpecificObjectCreator:IObjectCreator {     IObjectCreatorFactory objCreatorFactory;     public SpecificObjectCreator(IObjectCreatorFactory objCreatorFactory)     {         this.objCreatorFactory = objCreatorFactory;     }     T CreateObject<T>(IDataRow data)     {         T obj = new T;         ChildObject childObject = objCreatorFactory.GetObjectCreator(typeof(ChildObject)).CreateObject<ChildObject>(data);          .......     }     bool SupportsType(Type type);         } 

This does not work out. What would be the way to go for this scenario, where the created objects are refering back to the factory for child object creators?

  • 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. 2026-05-11T03:55:36+00:00Added an answer on May 11, 2026 at 3:55 am

    I would simply move the factory out of the constructors of the various specific object creators, and introduce a method on the IObjectCreator interface instead, responsible for initialising the creators:

    public interface IObjectCreator {     T CreateObject<T>(IDataRow data);     bool SupportsType(Type type);     void Initialize(IObjectCreatorFactory factory); } 

    And then just invoke Initialze(this) on each object creator passed into the factory.

    In the past I’ve used custom life cycle stages to take care of automatically invoking ‘post-construction’ setup of components to both avoid circular dependencies and also to take care of other associated concerns (i.e. applying additional component configuration from an external source like a database) – but it’s probably overkill for what you need.

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

Sidebar

Related Questions

So I downloaded and extracted the latest version of the Windsor IoC container today
The short question: Does Castle Windsor have something similar to Spring.Net's Lookup Method Injection
So I was searching the web looking for best practices when implementing the repository
I'm trying to implement a Generic Repository. This is what I've got so far
Prepare for a wall of code... It's a long read, but it's as verbose
Since the IoC/DI implementation in MVC 3 is most likely in its final form
I remember when ASP.NET MVC was new, there was a lot of contention over
I have an app, modelled on the one from Apress Pro ASP.NET MVC that
I have a View that uses RenderAction to render another View - it used
I think theres something really simple I'm missing so I apologize in advance. I'm

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.