static void Main(string[] args) { var container = new UnityContainer(); container.RegisterSingleton <UserMessageService>(); var router = UnityBuilder .FromContainer(container) .WithName("ExampleServer") .WithSerializer <DotNetSerializer>() .WithSerializer <JsonSerializer>(true, serializer => serializer.Settings.SerializationBinder = new NetCoreSerializationBinder()) .WithTransport <NetMQTransport>(t => { t.WithReceiver(TcpAddress.Localhost(5555)); t.WithPublisher(TcpAddress.Localhost(5556)); }) .WithHandlers(config => config .WithRequestHandler <UserConnecting, Response <User>, UserMessageService>() .WithRequestHandler <UserDisconecting, Response <User>, UserMessageService>() .WithRequestHandler <ConnectedUsers, ConnectedUsersList, UserMessageService>() .WithRequestHandler <PostMessage, Response <Message>, UserMessageService>()) .BuildAndStart(); Console.Title = "Chat Server"; Console.WriteLine("Press enter to stop server"); var server = container.Resolve <UserMessageService>(); var running = true; while (running) { var input = Console.ReadLine(); switch (input) { case "reset": server.Reset(); break; case "exit": running = false; break; } } router.Stop(); }
public static void Main(string[] args) { var container = new UnityContainer(); container .RegisterSingleton <UnityContainer>() .RegisterSingleton <App>() .RegisterSingleton <MessagingService>(); var router = UnityBuilder .FromContainer(container) .WithName("ExampleClient") .WithSerializer <DotNetSerializer>() .WithSerializer <JsonSerializer>(true) .WithTransport <NetMQTransport>(t => { t.WithSender(TcpAddress.Localhost(5555)) .For <UserConnecting>() .For <UserDisconecting>() .For <ConnectedUsers>() .For <PostMessage>(); t.WithSubscriber(TcpAddress.Localhost(5556)) .Handles <UserConnected>() .Handles <UserDisconnected>() .Handles <PostedMessage>(); }) .WithHandlers(c => { c.WithTopicHandler <UserConnected, MessagingService>() .WithTopicHandler <UserDisconnected, MessagingService>() .WithTopicHandler <PostedMessage, MessagingService>(); }) .BuildAndStart(); using (container.Resolve <MessagingService>()) { var app = container.Resolve <App>(); app.Container = container; app.InitializeComponent(); app.Run(); } router.Stop(); }