示例#1
0
        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();
        }
示例#2
0
        static void Main(string[] args)
        {
            UnityBuilder builder = new UnityBuilder(
                new List <ICar>(),
                new List <ITaxi>());

            Unity unity = builder.Build();

            Console.WriteLine("Sum of car prices is more than 5000:" + Taxi.GetSumPrice(Taxi.Find(unity.TaxiCollection, "TaxiCity").Items, a => a.Price > 5000));
            Console.WriteLine("Sum of car prices with fuel cost less than 8:" + Taxi.GetSumPrice(Taxi.Find(unity.TaxiCollection, 5814444).Items, (IOptionable b) => b.FuelCost < 8));
            Console.WriteLine(Taxi.Find(unity.TaxiCollection, "TaxiCity").ToString());
            IEnumerable <ICar> sortedCollectionCars = from car in Taxi.Find(unity.TaxiCollection, "TaxiCity").Items orderby(car as IOptionable).FuelCost select car;

            IEnumerable <ICar> selectedByMinSpeed    = (Taxi.Find(unity.TaxiCollection, "TaxiCity") as Taxi).SelectBySpeed(170);
            IEnumerable <ICar> selectedByMinMaxSpeed = (Taxi.Find(unity.TaxiCollection, "TaxiCity") as Taxi).SelectBySpeed(170, 180);
            //Taxi sortedCarsTaxi = new Taxi();
            //sortedCarsTaxi.Add ( sortedCollectionCars);
            //Console.WriteLine(sortedCarsTaxi.ToString());
        }
示例#3
0
 public Publisher()
 {
     router = UnityBuilder.Named("Publisher")
              .WithTransport <NetMQTransport>(t => t.WithPublisher(TcpAddress.Wildcard(5556)))
              .Build();
 }