首页 \ 问答 \ AppDomains之间的通信(Communication between AppDomains)

AppDomains之间的通信(Communication between AppDomains)

我们正在构建一个应用程序(WinForms,.NET 3.5),它将“插件”DLL加载到辅助AppDomain中。 辅助AppDomain需要偶尔与第一个AppDomain通信(更具体地说,从主AppDomain中创建的对象调用或获取数据)。

我已经阅读了有关AppDomains的大部分内容以及它们之间的通信。

到目前为止,我见过的唯一简单的解决方案是从MarshalByRefObject继承并将TransparentProxy传递到第二个AppDomain,在Proxy上调用方法。

此方法有其缺点(例如,在框架类型的情况下,或者从已经从其他类继承的类型,静态字段/类等等,并不总是可以从MBRO继承)。

由于当前的通信点非常不变(只有2-3个需要通信的场景),我考虑创建一个具有以下属性的简单Mediator类:

  1. 将在1st(Main)AppDomain中创建。
  2. 只能作为主要AppDomain中创建的“Real”对象的“消息传递器”。
  3. 将继承自MBRO,并将其代理引用发送到第二个AppDomain。

将调用此代理对象上的方法,然后调用第一个AppDomain中“真实”对象上的方法。

我的问题 -

  1. 这看起来像是一个逻辑设计吗?
  2. 更重要的是,WCF或任何其他通信框架中是否已存在调解器/消息传递器类? 它似乎是一个通用的概念,我想知道是否有类似的东西。

We are building an app (WinForms, .NET 3.5) that loads "Plugin" DLLs into a secondary AppDomain. The secondary AppDomain needs to communicate occasionally with the 1st one (more specifically, call or get data from objects that are created in the main AppDomain).

I have read most of the material about AppDomains and communication between them.

So far, the only easy solution i've seen was inheriting from MarshalByRefObject and passing a TransparentProxy into the 2nd AppDomain, calling methods on the Proxy.

This method has its drawbacks (not always possible to inherit from MBRO in case of framework types for example, or types that already inherit from another class, static fields/classes and so on).

Since the current communication points are pretty constant (only 2-3 scenarios that require communication), i have considered creating a simple Mediator class with the following properties:

  1. Will be created in the 1st (Main) AppDomain.
  2. Would function only as a "message-passer" to the "Real" objects that are created in the main AppDomain.
  3. Will inherit from MBRO, and a proxy reference to it will be sent to the 2nd AppDomain.

Methods on this proxy object would be called, which in turn will call the methods on the "real" objects in the 1st AppDomain.

My questions --

  1. Does this seem like a logical design?
  2. More importantly, does a mediator/message passer class already exist in WCF or any other communcation framework? it seems like a generic concept and i am wondering if there is something similar.

原文:https://stackoverflow.com/questions/8972352
更新时间:2023-11-07 17:11

最满意答案

您必须实际调用之前设置方法期望,因此您的测试应如下所示:

context "Get #show" do
  subject { get :show, school_id: school.id, id: user.id }

  it "calls +authorize+ befor action" do
    expect(controller).to receive(:authorize)
    subject
  end
end

查看文档https://github.com/rspec/rspec-mocks#message-expectations


You must set method expectation before actual call, so your test should look like:

context "Get #show" do
  subject { get :show, school_id: school.id, id: user.id }

  it "calls +authorize+ befor action" do
    expect(controller).to receive(:authorize)
    subject
  end
end

Check the documentation https://github.com/rspec/rspec-mocks#message-expectations

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)