Skip to content

Commit 6c8aafd

Browse files
committed
Decorate proxies w/ ServiceProxy and use ServiceProxyRegistrationBehavior in ConsoleUi
1 parent 115c7a2 commit 6c8aafd

6 files changed

Lines changed: 70 additions & 6 deletions

File tree

InterProcessCommunication/TradingApp/.Notes/PresentationScript.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,41 @@ <h4 id="implement-proxies-to-call-the-services-as-a-rest-api">8. Implement proxi
227227
<li>--&gt; we need some prioritization for AppBoot (see next step)</li>
228228
</ul>
229229
</li>
230+
</ul>
231+
<h4 id="implement-servicepoxyattribute-and-serviceproxyregistrationbehavior">9. Implement <code>ServicePoxyAttribute</code> and <code>ServiceProxyRegistrationBehavior</code></h4>
232+
<ul>
233+
<li>Create the <code>AppBootEx</code> csproj</li>
234+
<li>Create <code>ServicePoxyAttribute</code> from scrach</li>
235+
<li>Create <code>ServiceProxyRegistrationBehavior</code>:</li>
236+
</ul>
237+
<pre><code class="language-csharp"> public sealed class ServiceProxyRegistrationBehavior : IRegistrationBehavior
238+
{
239+
public IEnumerable&lt;ServiceInfo&gt; GetServicesFrom(Type type)
240+
{
241+
IEnumerable&lt;ServiceProxyAttribute&gt; attributes = type.GetAttributes&lt;ServiceProxyAttribute&gt;(false);
242+
return attributes.Select(a =&gt; new ServiceInfo(a.ExportType, type, string.Empty, Lifetime.AlwaysNew));
243+
}
244+
}
245+
</code></pre>
246+
<ul>
247+
<li>Add <code>ServiceProxyRegistrationBehavior</code> in the <code>Program.cs</code> at <code>AppBoot.Bootstrapp()</code>
248+
<ul>
249+
<li>the last added registration behavior, overwrites</li>
250+
</ul>
251+
</li>
252+
</ul>
253+
<p><strong>Points:</strong></p>
254+
<ul>
255+
<li>we have now the wanted behavior: <strong>Based on deployment we have <em>in-process</em> or <em>inter-process</em> communication</strong>
256+
<ul>
257+
<li>demo this with <code>ConsoleUi</code>
258+
<ul>
259+
<li>if implementations are deployed <strong>everythign</strong> is in one process</li>
260+
<li>if we delete the implementations from the <code>\bin\</code> then we have <em>inter-process</em> communication with the Console Host!</li>
261+
</ul>
262+
</li>
263+
</ul>
264+
</li>
230265
</ul>
231266

232267
</div>

InterProcessCommunication/TradingApp/.Notes/PresentationScript.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,30 @@ class QuotationService : IQuotationService
151151
- but! the `PortfolioService` may get a proxy to call the `QuotationService` this result in a *inter-process* communitcation between `PortfolioSerivce` and `QuotationService`
152152
- ex2:
153153
- `ConsoleUi` loads only proxies, the communication between `PortfolioSerivce` and `QuotationService` happens on the `ConsoleHost` only, in process!
154-
- --> we need some prioritization for AppBoot (see next step)
154+
- --> we need some prioritization for AppBoot (see next step)
155+
156+
#### 9. Implement `ServicePoxyAttribute` and `ServiceProxyRegistrationBehavior`
157+
158+
- Create the `AppBootEx` csproj
159+
- Create `ServicePoxyAttribute` from scrach
160+
- Create `ServiceProxyRegistrationBehavior`:
161+
```csharp
162+
public sealed class ServiceProxyRegistrationBehavior : IRegistrationBehavior
163+
{
164+
public IEnumerable<ServiceInfo> GetServicesFrom(Type type)
165+
{
166+
IEnumerable<ServiceProxyAttribute> attributes = type.GetAttributes<ServiceProxyAttribute>(false);
167+
return attributes.Select(a => new ServiceInfo(a.ExportType, type, string.Empty, Lifetime.AlwaysNew));
168+
}
169+
}
170+
```
171+
172+
- Add `ServiceProxyRegistrationBehavior` in the `Program.cs` at `AppBoot.Bootstrapp()`
173+
- the last added registration behavior, overwrites
174+
175+
176+
**Points:**
177+
- we have now the wanted behavior: **Based on deployment we have *in-process* or *inter-process* communication**
178+
- demo this with `ConsoleUi`
179+
- if implementations are deployed **everythign** is in one process
180+
- if we delete the implementations from the `\bin\` then we have *inter-process* communication with the Console Host!

InterProcessCommunication/TradingApp/ConsoleUi/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Net.Sockets;
66
using System.Reflection;
77
using System.Web;
8+
using AppBootEx;
89
using Contracts.Infrastructure;
910
using Contracts.Portfolio.Services;
1011
using Contracts.Quotations.Services;
@@ -35,6 +36,7 @@ private static IServiceLocator Bootstrapp()
3536
var assemblies = GetApplicationAssemblies().ToArray();
3637
Bootstrapper bootstrapper = new Bootstrapper(assemblies);
3738
bootstrapper.ConfigureWithUnity();
39+
bootstrapper.AddRegistrationBehavior(new ServiceProxyRegistrationBehavior());
3840
bootstrapper.AddRegistrationBehavior(new ServiceRegistrationBehavior());
3941

4042
bootstrapper.Run();

InterProcessCommunication/TradingApp/Infrastructure/Proxies/OrdersServiceProxy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System;
22
using System.Net.Http;
33
using System.Web;
4+
using AppBootEx;
45
using Contracts.Sales.Services;
56
using iQuarc.AppBoot;
67

78
namespace Proxies
89
{
9-
[Service(typeof(IOrdersService))]
10+
[ServiceProxy(typeof(IOrdersService))]
1011
class OrdersServiceProxy : IOrdersService
1112
{
1213
public void PlaceSellLimitOrder(string securityCode, decimal sellingPrice, DateTime validUntil)

InterProcessCommunication/TradingApp/Infrastructure/Proxies/PortfolioServiceProxy.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System.Net.Http;
22
using System.Web;
3+
using AppBootEx;
34
using Contracts.Portfolio.Services;
4-
using Contracts.Quotations.Services;
5-
using iQuarc.AppBoot;
65

76
namespace Proxies
87
{
9-
[Service(typeof(IPortfolioService))]
8+
[ServiceProxy(typeof(IPortfolioService))]
109
class PortfolioServiceProxy : IPortfolioService
1110
{
1211
public decimal GetPortfolioValue()

InterProcessCommunication/TradingApp/Infrastructure/Proxies/QuotationServiceProxy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System;
22
using System.Net.Http;
33
using System.Web;
4+
using AppBootEx;
45
using Contracts.Portfolio.Services;
56
using Contracts.Quotations.Services;
67
using iQuarc.AppBoot;
78

89
namespace Proxies
910
{
10-
[Service(typeof(IQuotationService))]
11+
[ServiceProxy(typeof(IQuotationService))]
1112
class QuotationServiceProxy : IQuotationService
1213
{
1314
public Quotation[] GetQuotations(string exchange, string instrument, DateTime @from, DateTime to)

0 commit comments

Comments
 (0)