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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:36:28+00:00 2026-05-11T02:36:28+00:00

I am working in a project that has two main parts: a class library

  • 0

I am working in a project that has two main parts: a class library assembly and the main application. Both are using Castle Windsor for IoC and both manually setup their list of of components in code (to aid refactoring and prevent the need for a config file). Currently the main application has code like this:

public static void Main() {             // Perform library IoC setup     LibraryComponent.Init();      // Perform application IoC setup     IoC.Register<IXyz, Abc>('abc');     // etc, etc, ...      // Start the application code ... } 

However the call to initialise the library doesn’t seem like a good solution. What is the best way to setup a class library that uses an IoC container to decouple its internal components?


Edit:

  • Lusid proposed using a static method on each public component in the library that would in turn make the call to initialise. One possible way to make this a bit nicer would be to use something like PostSharp to do this in an aspect-oriented way. However I was hoping for something a bit more elegant 😉

  • Lusid also proposed using the AppDomain.AssemblyLoad event to perform custom steps at load time, however I am really after a way to avoid the client assembly from requiring any setup code.

Thanks!

  • 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-11T02:36:29+00:00Added an answer on May 11, 2026 at 2:36 am

    I’m not sure if I’m understanding exactly the problem you are trying to solve, but my first guess is that you are looking for a way to decouple the need to call the Init method from your main application.

    One method I’ve used in the past is a static constructor on a static class in the class library:

    static public class LibraryComponent {   static LibraryComponent() {     Init();   } } 

    If you have multiple class libraries, and would like a quick and dirty way of evaluating all of them as they are loaded, here’s a (kinda hairy) way:

    [STAThread] static void Main() {     AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad); }  static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) {     IEnumerable<Type> types = args.LoadedAssembly.GetTypes()         .Where(t => typeof(IMyModuleInterface).IsAssignableFrom(t));     foreach (Type t in types)     {         doSomethingWithType(t);     } } 

    The Where clause could be anything you want, of course. The code above would find any class deriving from IMyModuleInterface in each assembly that gets loaded into the current AppDomain, and then I can do something with it, whether it be registering dependencies, maintaining an internal list, whatever.

    Might not be exactly what you are looking for, but hopefully it helps in some way.

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

Sidebar

Related Questions

First, I have two project working on: ASP.NET and Silverlight Both uses a class
I'm working on an ASP.net 3.5 project that has evolved out of a Classic
So recently I have been working on phonebook project that uses Binary Search Tree.
I have been working on a project that requires downloading a zipped file off
We are working on a project where we are using Spring 3 to create
Still working on a web application as a school project, and it just seems
I am currently working on an amateur physic engine for a school project but
I'm working on a project which uses Twisted to provide a high performance UDP
I'm really struggling to get my head around the idea of working with a
I'm trying out git for local workflow management, with an eye toward proposing it

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.