Skip to content

Allows creating proxy objects that look exactly like the original objects.

License

Notifications You must be signed in to change notification settings

HavenDV/H.ProxyFactory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Language License Requirements Build Status

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

Nuget

NuGet

Install-Package H.ProxyFactory.Pipes

Usage

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!");

1

Contacts