caSTLe-windsor - 我可以告诉 CaSTLe Windsor 在单独的 AppDomain 中创建组件吗?

标签 castle-windsor appdomain

我创建了一个多线程服务,它使用 CaSTLe Windsor 创建在单独线程上运行的组件。我通过每个线程的名称和参数解析组件。

我遇到了组件使用的第 3 方库的并发问题。我怀疑将这些组件隔离在单独的 AppDomain 中可以解决问题。

有没有办法让 Resolve 使用不同的 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();
    }
}

最佳答案

关于caSTLe-windsor - 我可以告诉 CaSTLe Windsor 在单独的 AppDomain 中创建组件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1329618/

相关文章:

c# - 使用 CaSTLe Windsor 在 WebAPI 中进行依赖注入(inject)

c# - 从应用程序域中删除程序集

c# - 如何在 Windows 窗体的构造函数中注入(inject)依赖项

c# - 如何拦截 CaSTLe Windsor 的组件解析来覆盖依赖?

caSTLe-windsor - 如何在 CaSTLe 3 中恢复旧的 CollectionResolver 行为?

caSTLe-windsor - CaSTLe Windsor 3 Interceptor 不发布由类型化工厂创建的组件,但 2.5.4 发布了。为什么?

c# - 在 appdomain 中加载静态类

Azure 环境中的 IIS AppDomain 卸载

c# - 枚举所有没有 mscoree 的 AppDomains

c# - AppDomain 是否等同于 .NET 代码的进程?