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 8415665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:30:41+00:00 2026-06-10T01:30:41+00:00

I have the following castle windsor fluent config code … container .AddFacility<TypedFactoryFacility>() .Register( Component

  • 0

I have the following castle windsor fluent config code …

container
  .AddFacility<TypedFactoryFacility>()
  .Register(

  Component
    .For<IXxxCache>()
    .ImplementedBy<AppFabricXxxCache>()
    .Named("AppFabricXxxCache")
    .LifeStyle.FromContext(),

  Component
    .For<IXxxCache>()
    .ImplementedBy<DatabaseXxxCache>()
    .Named("DatabaseXxxCache")
    .LifeStyle.FromContext(),

  Component
    .For<IXxxCacheFactory>()
    .ImplementedBy<XxxCacheFactory>()
    .DependsOn(new {cacheName})
  );

The XxxCacheFactory is as follows …

public class XxxCacheFactory : IXxxCacheFactory
{
    private readonly IWindsorContainer _container;
    private readonly string _cacheName;

    public XxxCacheFactory(IWindsorContainer container, string cacheName)
    {
        _container = container;
        _cacheName = cacheName;
    }

    public IXxxCache Create()
    {
        try
        {
            var cache = new DataCacheFactory().GetCache(_cacheName);
            return _container.Resolve<IXxxCache>("AppFabricXxxCache", new {cache});
        }
        catch (DataCacheException)
        {
            return _container.Resolve<IXxxCache>("DatabaseXxxCache");
        }
    }

    public void Release(IXxxCache component)
    {
        _container.Release(component);
    }
}

I can get this working with the following code …

[Test]
public void database_xxx_cache_returned_when_cache_does_not_exist()
{
    ConfigurationManager.AppSettings["CacheName"] = "this_cache_does_not_exist";
    var container = Castle.WindsorContainerBootStrap.BootStrapContainerAndRunInstallers<SingletonLifestyleManager>();
    var factory = container.Resolve<IXxxCacheFactory>();
    var cache = factory.Create();
}

Ideally I’d like to cut out the factory creation part and just have the container get the the correct implementation using the factory class I have, like so …

[Test]
public void database_xxx_cache_returned_when_cache_does_not_exist()
{
    ConfigurationManager.AppSettings["CacheName"] = "this_cache_does_not_exist";
    var container = Castle.WindsorContainerBootStrap.BootStrapContainerAndRunInstallers<SingletonLifestyleManager>();
    var cache = container.Resolve<IXxxCache>();
}

Is this possible? If so, what am I missing?

  • 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-10T01:30:42+00:00Added an answer on June 10, 2026 at 1:30 am

    One of my colleagues pointed me at the factory method support of Windsor

    Just adding this to my installer has got it working …

    container
        .Register(
            Component
                .For<DataCacheFactory>()
                .ImplementedBy<DataCacheFactory>()
                .LifeStyle.Singleton
            ,
            Component
                .For<IXxxCacheFactory>()
                .ImplementedBy<XxxCacheFactory>()
                .DependsOn(new {cacheName})
                .LifeStyle.Transient
            ,
            Component
                .For<IXxxCache>()
                .UsingFactoryMethod(kernel => kernel.Resolve<IXxxCacheFactory>().Create())
            ,
            Component
                .For<IXxxCache>()
                .ImplementedBy<AppFabricXxxCache>()
                .Named("AppFabricXxxCache")
                .LifeStyle.FromContext()
            ,
            Component
                .For<IXxxCache>()
                .ImplementedBy<DatabaseXxxCache>()
                .Named("DatabaseXxxCache")
                .LifeStyle.FromContext()
         );
    

    I’ve also used the container to create the DataCacheFactory as that is apparently an expensive operation. So the usage is now …

    [Test]
    public void database_xxx_cache_returned_when_cache_does_not_exist()
    {
        // ARRANGE
        ConfigurationManager.AppSettings["CacheName"] = "this_cache_does_not_exist";
        var container = Castle.WindsorContainerBootStrap.BootStrapContainerAndRunInstallers<SingletonLifestyleManager>();
    
        // ACT
        var cache = container.Resolve<IXxxCache>();
    
        // ASSERT
        Assert.That(cache, Is.InstanceOf<DatabaseXxxCache>());
    
        // TIDYUP
        container.Dispose();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Castle Windsor as my IoC container and NHibernate I have the following registration:
I have written the following simple test in trying to learn Castle Windsor's Fluent
I have the following situation Project A - Uses Castle Windsor v2.2 - Uses
I have the following mapping in my Castle Windsor xml file which has worked
I have the following component mapping in Windsor xml: <component id=dataSession.DbConnection service=System.Data.IDbConnection, System.Data, Version=2.0.0.0,
I am learning castle.windsor following the tutorial online. this is the simple sample code:
With Castle Windsor, let's say I have the following classes: public class LowLevelComponent {
I have inherited a code base that makes use of the Castle Windsor IoC
I use Castle Windsor as my IoC container . I have an application that
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig

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.