Can I tell Castle Windsor to create a component in a separate AppDomain?

I created a multi-threaded service that uses Castle Windsor to create components to run on separate threads. I resolve component by name with parameters for each thread.

I ran into concurrency issues with a third party library used by components. I suspect that separating these components into separate AppDomains will solve the problem.

Is there a way to allow component creation using a different AppDomain?

private ActivityThread NewActivityThread(ActivityInstance activityInstance)
{
    // Set up the creation arguments.
    System.Collections.IDictionary arguments = new Dictionary<string, string>();
    activityInstance.Parameters.ForEach(p => arguments.Add(p.Name, p.Value));

    // Get the activity handler from the container.
    IActivity activity = Program.Container.Resolve<IActivity>(activityInstance.Name, arguments);

    // Create a thread for the activity.
    ActivityThread thread = new ActivityThread(activity, activityInstance, _nextActivityID++);
    return thread;
}

public ActivityThread(IActivity activity, ActivityInstance instance, int id)
{
    _activity = activity;
    _instance = instance;
    _id = id;
}

public void Start()
{
    if (_thread == null)
    {
        // Create a new thread to run this activity.
        _thread = new Thread(delegate() { _activity.Run(); });
        _thread.Name = _activity.ToString();
        _thread.SetApartmentState(ApartmentState.STA);
        _thread.Start();
    }
}

      

+2


source to share


2 answers


If you've already created a separate AppDomain, can't you just create a new instance of the Windsor container in the private AppDomain?



+1


source


+2


source







All Articles