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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:58:37+00:00 2026-05-21T11:58:37+00:00

I was exploring the installer functionality of Castle Windsor based on the answers from

  • 0

I was exploring the installer functionality of Castle Windsor based on the answers from a related question. I want to use the Web.config to specify the name of the database and I would rather not explicitly set the database name in my code. I tried Krzysztof Koźmic’s example and when I debut the project my break-point at container.Register gets hit, but the dependency is still not resolved:

public class RepositoriesInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(AllTypes.FromThisAssembly()
                            .Where(Component.IsInSameNamespaceAs<SqlUsersRepository>())
                            .WithService.DefaultInterface()
                            .Configure(c => c.LifeStyle.Transient
                            .DependsOn(new { databaseName = "MyDatabaseName" })));
    }
}

Sanders suggests that we can use the Web.config to resolve dependencies (note that he’s doing this to get the connection string, but my connection string is encrypted so I’m doing in in a slightly different way):

<castle>
    <components>
      <component id="SqlUsersRepository"
          service="MyDevArmyModel.Entities.IUsersRepository, MyDevArmyModel"
          type="MyDevArmyModel.Entities.SqlUsersRepository, MyDevArmyModel">
        <parameters>
          <databaseName>MyDatabaseName</databaseName>
        </parameters>
      </component>
    </components>
</castle>

My SqlUsersRepository and IUsersRepository are in the same namespace, but they’re part of a class library which gets referenced in the current project. SqlUsersRepository looks up the connection string from the Web.Config the database name:

public interface IUsersRepository
{
    IQueryable<User> Users { get; }
    // ...
    // and some other things 
    // ...

}

public class SqlUsersRepository : IUsersRepository
{
    private DataContext dataContext;
    private Table<User> usersTable;

    public IQueryable<User> Users { get { return usersTable; } }

    public SqlUsersRepository(string databaseName)
    {
        HttpRequestWrapper request = new HttpRequestWrapper(System.Web.HttpContext.Current.Request);
        Configuration config = WebConfigurationManager.OpenWebConfiguration(request.ApplicationPath);
        dataContext = new DataContext(config.GetConnetionString(databaseName));
        usersTable = dataContext.GetTable<User>();
    }

    // .... the rest of the repository goes here
}

Any help on this?

P.S.

I’m still getting an exception, even if I use the hard-coded database name (as seen in the RepositoriesInstaller):

Server Error in ‘/’ Application. Can’t
create component
‘MyProjectName.Controllers.UserController’
as it has dependencies to be
satisfied.
MyProjectName.Controllers.UserController
is waiting for the following
dependencies:

Services:
– MyProjectName.Entities.IUsersRepository
which was not registered. Description:
An unhandled exception occurred during
the execution of the current web
request. Please review the stack trace
for more information about the error
and where it originated in the code.

Exception Details:
Castle.MicroKernel.Handlers.HandlerException:
Can’t create component
‘MyProjectName.Controllers.UserController’
as it has dependencies to be
satisfied.
MyProjectName.Controllers.UserController
is waiting for the following
dependencies:

Services:
– MyProjectName.Entities.IUsersRepository
which was not registered.

Update
I’ve posted an answer which addresses the exception problem, but I’m yet to figure out how to use the Web.config to store Castle Windsor specific sections.

  • 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-05-21T11:58:37+00:00Added an answer on May 21, 2026 at 11:58 am

    You should be able to achieve this by reducing the XML to this:

    <castle>
        <components>
          <component id="SqlUsersRepository">
            <parameters>
              <databaseName>MyDatabaseName</databaseName>
            </parameters>
          </component>
        </components>
    </castle>
    

    and then make sure your registration registers the repository under the right key/id – e.g. like this:

    container.Register(AllTypes(...).Configure(c => c.Named(c.Implementation.Name)))
    

    where all keys will be set to the short name of each concrete type.

    Please note that this naming scheme might not be appropriate for you, so you should probably adapt the c.Named(...) to whatever you deem right for your use case. Just make sure that the registration key for your repository matches that if the id attribute in the XML.

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

Sidebar

Related Questions

I'm exploring the XML -> XSLT -> HTML meme for producing web content. I
I've been exploring use of MSys lately as an alternative, 'nix-like shell for my
while exploring jQuery I came up with the following weird script. I don't see
I'm exploring the possibility of writing an application in Erlang, but it would need
I've been exploring different strategies for running integration tests within some Nant build scripts.
I'm thinking about exploring the idea of having our client software run as a
I have recently started exploring Maven, but I feel a bit overwhelmed of all
I'm exploring the possibility of running a Java app on a machine with very
Does anyone know of a good open source plugin for database querying and exploring
I am writing a Tomcat app. As part of its functionality, it needs to

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.