Allows you to interact with remote objects. You will have access to an interface through which you will interact with the object created on the server.
Features:
- Create proxy objects that look exactly like the original objects
- Proxy target can be located anywhere where there is access to pipes
Install-Package H.ProxyFactory.Pipes
Shared code:
public interface IActionService
{
void SendText(string text);
void ShowTrayIcon();
void HideTrayIcon();
event EventHandler<string> TextReceived;
}
public class ActionService { }
Implementation in the server project:
public class ActionService : IActionService
{
private TrayIconService trayIconService = new();
public void SendText(string text)
{
Console.WriteLine($"Text from client: {text}");
TextReceived?.Invoke(this, "Hi from server");
}
public void ShowTrayIcon()
{
trayIconService.ShowTrayIcon();
}
public void HideTrayIcon()
{
trayIconService.HideTrayIcon();
}
public event EventHandler<string>? TextReceived;
}
Server:
await using var server = new PipeProxyServer();
await server.InitializeAsync("UniquePipeServerName");
Client:
await using var factory = new PipeProxyFactory();
await factory.InitializeAsync("UniquePipeServerName");
// You will have access to an interface through which you will interact with the object created on the server.
var service = await factory.CreateInstanceAsync<ActionService, IActionService>();
instance.TextReceived += (_, text) =>
{
WriteLine($"{nameof(instance.TextReceived)}: {text}");
};
instance.ShowTrayIcon();
Instance.SendText("hello!");