コード例 #1
1
ファイル: Program.cs プロジェクト: mahizsas/Simple.ServiceBus
        static void Main(string[] args)
        {
            var container = new ContainerBuilder()
                .RegisterServiceBus()
                .RegisterHandlers(System.Reflection.Assembly.GetExecutingAssembly())
                .ListenFor<SimpleMessage>()
                .Subscribe<SimpleMessage>(x => Console.WriteLine(string.Format("Received (delegate) '{0}' with message id of {1}", x.Title, x.Id)))
                .Build();

            var serviceBus = container.Resolve<IServiceBus>();

            Console.Write("Message: ");
            var message = Console.ReadLine();

            while (!string.IsNullOrEmpty(message))
            {
                serviceBus.Publish(new SimpleMessage
                {
                    Title = message,
                    Id = Guid.NewGuid()
                });

                Console.Write("Message:");
                message = Console.ReadLine();
            }
        }
コード例 #2
0
        private static async void Run()
        {
            var container = new ContainerBuilder()
                .RegisterServiceBus()
                .Build();

            var serviceBus = container.Resolve<IServiceBus>();
            var manager = container.Resolve<IServiceBusManager>();

            Console.WriteLine("Resetting demo topic...");
            await manager.DeleteTopicAsync<SimpleMessage>();
            Console.Write("Message: ");
            var message = Console.ReadLine();
            Console.Write("Sending messages...");
            await Send(serviceBus, message);
            Console.WriteLine("Done. Press any key to exit.");
            Console.ReadLine();
            ResetEvent.Set();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: mahizsas/Simple.ServiceBus
        static void Main(string[] args)
        {
            var container = new ContainerBuilder()
                .RegisterServiceBus()
                .RegisterHandlers(System.Reflection.Assembly.GetExecutingAssembly())
                .Builder.Build();

            var serviceBus = container.Resolve<IServiceBus>();
            serviceBus.Subscribe(new Handler<SimpleMessage>(x => Console.WriteLine(string.Format("Received (delegate) '{0}' with message id of {1}", x.Title, x.Id))));
            Console.WriteLine("Waiting for messages.....");
            var message = Console.ReadLine();
        }
コード例 #4
0
ファイル: AutofacFixture.cs プロジェクト: NuPattern/CodeFirst
        public void when_creating_non_registered_instance_then_can_add_registration_on_the_fly()
        {
            var container = new ContainerBuilder().Build();

            var builder = new ContainerBuilder();
            builder.RegisterType(typeof(Global)).AsSelf().AsImplementedInterfaces();
            builder.Update(container);

            Assert.True(container.IsRegistered(typeof(Global)));

            container.Resolve<Global>();
        }
コード例 #5
0
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            var container = new ContainerBuilder().Build();
            var userServices = container.Resolve<IUserServices>();
            var securityHelper = container.Resolve<ISecurityHelper>();
            var token = filterContext.Request.Headers.Authorization.Parameter;
            var userId = securityHelper.GetUserIdForToken(token);
            var user = userServices.FindUserById(userId);

            if (user.AccessToken != token)
            {
                Trace.TraceError("[VerifyTokenAttribute] Invalid Access Token: " + token);
                filterContext.Response = filterContext.Request.CreateResponse(
                    HttpStatusCode.InternalServerError,
                    new ErrorDto
                    {
                        Code = int.Parse(ControllerErrorCodes.TokenMismatch),
                        Error = ControllersErrorMessages.TokenMismatch
                    }
                    );
            }
        }
コード例 #6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Schedulers.Initialise();

            var container = new ContainerBuilder()
                .AddModulesFromAssembly(Assembly.GetExecutingAssembly())
                .Build();

            var viewModel = container.Resolve<MainWindowViewModel>();
            var window = new MainWindow() { DataContext = viewModel};

            window.Show();
        }
コード例 #7
0
ファイル: ResolveFixture.cs プロジェクト: arronchen/Autofac
 public void FailedResolve()
 {
     // Issue #376: MissingManifestResourceException thrown when a ComponentNotRegisteredException is thrown.
     var container = new ContainerBuilder().Build();
     Assert.Throws<ComponentNotRegisteredException>(() => container.Resolve<ISimpleService>());
 }
コード例 #8
0
ファイル: AutofacTests.cs プロジェクト: ChrisFulstow/Idiocy
 public void Autofac_Throw_If_Service_Not_Registered()
 {
     var container = new ContainerBuilder().Build();
     var component = container.Resolve<IServiceWithParams>();
 }