git ch ipc-step0(before)
Points :
IQuotationService in ContractsPoints:
public class Quotation
{
public DateTime Timestamp { get; set; }
public decimal BidPrice { get; set; }
public decimal AskPrice { get; set; }
public string SecurityCode { get; set; }
}
git ch ipc-step1(after)
QuotationService in QuotationModuleclass QuotationService : IQuotationService
{
private readonly Quotation[] array =
{
new Quotation {AskPrice = 10.50m, BidPrice = 10.55m, SecurityCode = "ING.S.NYSE"},
new Quotation {AskPrice = 12.50m, BidPrice = 12.55m, SecurityCode = "ING.B.NYSE"},
new Quotation {AskPrice = 10.70m, BidPrice = 10.75m, SecurityCode = "AAPL.B.NASDAQ"},
new Quotation {AskPrice = 11.50m, BidPrice = 11.55m, SecurityCode = "AAPL.S.NASDAQ"},
new Quotation {AskPrice = 16.50m, BidPrice = 16.55m, SecurityCode = "MSFT.B.NASDAQ"},
new Quotation {AskPrice = 17.50m, BidPrice = 17.55m, SecurityCode = "ING.B.AEX"},
new Quotation {AskPrice = 10.51m, BidPrice = 10.59m, SecurityCode = "ING.S.AEX"},
};
public Quotation[] GetQuotations(string exchange, string instrument, DateTime @from, DateTime to)
{
var result = array.Where(q => q.SecurityCode.Contains(exchange));
if (!string.IsNullOrWhiteSpace(instrument))
result = result.Where(q => q.SecurityCode.Contains(instrument));
return result.ToArray();
}
public Quotation[] GetQuotations(string securityCode, DateTime @from, DateTime to)
{
return array.Where(q => q.SecurityCode == securityCode).ToArray();
}
}
git ch ipc-step2(after)
OrderingService in SalesModuleIQuotationServicePoints:
public interface IOrdersService
{
void PlaceSellLimitOrder(string securityCode, decimal sellingPrice, DateTime validUntil);
void PlaceBuyLimitOrder(string securityCode, decimal buyingPrice, DateTime validUntil);
LimitOrder[] GetLimitOrders();
}
public class LimitOrder
{
public string SecurityCode { get; set; }
public DateTime PlacedAt { get; set; }
public OrderType Type { get; set; }
public decimal Price { get; set; }
public DateTime ValidUntil { get; set; }
}
public enum OrderType
{
Sell,
Buy
}
git ch ipc-step3(after)
PortfolioService in PortfolioModulePoints:
Contracts assembly because it will be called from the UI, which will be hosted in a different process.(the point of this demo is not necessarely the communication between BE and FE, which might be done differently from the communication between BE components.However in most cases it is done in the same way, therefore it makes sense to add it in contracts.)
git ch ipc-step4(after)
Show that at this point the modules and services are not linked
A lightweight library that handles the startup of an app. We benefit for two main aspects
Install iQuarc.AppBoot for the projects in \Modules\
iQuarc.AppBoot.Unity is installed only in the host (the rest do not need to depend on Unity)The ConsoleHost be the process that will host the BE services
git ch ipc-step5(adds ConsoleUi withIPortfolioService)
IPortfolioService as example and explain how it should be resolved through DI / ServiceLocator
git ch ipc-step6(before)
bin folder, so they can be loaded in Debug envServiceAttribute
git ch ipc-step6a(ConsoleUi completed)
Points
Install-Package Microsoft.AspNet.WebApi.OwinSelfHostInstall-Package iQuarc.AppBoot.WebApi
git ch ipc-step7(basic Web API self host)
IQuotationService it publishes it
git ch ipc-step7a(to show below: QuotationService published)
git ch ipc-step7b(to show below)
Points:
References only to Contracts Look at the Project Dependency Diagram
ConsoleUi and ConsoleHost load the QuotationServices (and all of the other services) in their process.
When someone calls the /api/Portfolio/ the PortfolioService impl calls (in process) the IQuotationsService
They do Type Discovery: the implementation is loaded only if its dll is deployed
The QuotationsController could be generalized to have a generic host for all services it finds
OrdersController, PortfolioController)PublicServiceAttribute : ServiceAttribute to find themAppBoot could be extended to know about the PublicServiceAttribute and make the registration based on it too
git ch ipc-step8(to show below)
Infrastructure)Microsoft.AspNet.WebApi.Client
git ch ipc-step8a(to show below)
PortfolioServiceProxy as being the simplest
Portfolio.csproj but on the proxy
git ch ipc-step8b(before points, to show below)
Points:
ConsoleUi loads service implementations AND / OR proxies
ConsoleUi may act like a FE app if does not load service implementations.
ConsoleUi may call services in-process or inter-process
PortfolioService and w/ QuotationServicePortfolioServiceProxy othewise the non-deterministic behavior may make this tricky to demo)
ConsoleUi loads the QuotationServices.dll and PortfolioService.dll we would expect a in-process communicationPortfolioService may get a proxy to call the QuotationService this result in a inter-process communitcation between PortfolioSerivce and QuotationServiceConsoleUi loads only proxies, the communication between PortfolioSerivce and QuotationService happens on the ConsoleHost only, in process!ServicePoxyAttribute and ServiceProxyRegistrationBehavior
git ch ipc-step9(below points. Start coding, thench)
AppBootEx csprojServicePoxyAttribute from scrachServiceProxyRegistrationBehavior:public sealed class ServiceProxyRegistrationBehavior : IRegistrationBehavior
{
public IEnumerable<ServiceInfo> GetServicesFrom(Type type)
{
IEnumerable<ServiceProxyAttribute> attributes = type.GetAttributes<ServiceProxyAttribute>false);
return attributes.Select(a => new ServiceInfo(a.ExportType, type, string.Empty, ifetime.AlwaysNew));
}
}
git ch ipc-step9a(below points)
ServiceProxyRegistrationBehavior in the Program.cs at AppBoot.Bootstrapp()
ServiceProxyAttributePoints:
ConsoleUi
\bin\ then we have inter-process communication with the Console Host!ServiceProxyRegistrationBehavior to ConsoleHost and host each service in its own process
git ch ipc-step10(below points. Start coding, thench)
Register the service behavior and load the Proxies dll:
AppBootBootstrapper.cs add:
.AddRegistrationBehavior(new ServiceProxyRegistrationBehavior());|| filename.StartsWith("Proxies.")To have more instnaces of the ConsoleHost, and allow distributed system for the BE we need to:
app.config different ports for each service
git ch ipc-step10a
Points:
Inter-process / In-process communication ONLY throug deployment
st-10, and build the entire solution and run startAll.bat)Quotation.Services.dll into the bin of the Sales server and repeat the callsProxiesLook at the Project Dependency Diagram
ConsoleUi and ConsoleHost) do NOT referens the modules. They don't know what they will host. They can host anythingContracts and are linked by the InfrastructureOpen Points / Questions:
When 'ConsoleHost' loads Sales and Quotation modules it publishes all their services. This means that even if Quotation services are publised by another host, someone could call it from the Sales host
Local services should also be wrapeed in Proxies for in-process calls.