コード例 #1
0
ファイル: Program.cs プロジェクト: BredStik/MediatR
        private static IMediator BuildMediator()
        {
            var container = new Container(cfg =>
            {
                cfg.Scan(scanner =>
                {
                    scanner.AssemblyContainingType<Ping>();
                    scanner.AssemblyContainingType<IMediator>();
                    scanner.WithDefaultConventions();
                    scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
                    scanner.AddAllTypesOf(typeof(IAsyncRequestHandler<,>));
                    scanner.AddAllTypesOf(typeof(INotificationHandler<>));
                    scanner.AddAllTypesOf(typeof(IAsyncNotificationHandler<>));
                });
                cfg.For<TextWriter>().Use(Console.Out);
            });

            var serviceLocator = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            container.Configure(cfg => cfg.For<ServiceLocatorProvider>().Use(serviceLocatorProvider));

            var mediator = serviceLocator.GetInstance<IMediator>();

            return mediator;
        }
コード例 #2
0
        public UnityConnectionDependencyResolver(IUnityContainer container)
        {
            _container = container;
            ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);

            ServiceLocator.SetLocatorProvider(sp);
        }
コード例 #3
0
        public async Task Startup(ServiceLocatorProvider locatorProvider,
            IDependencyContainer container,
            Action<IDependencyContainer> buildDependencies = null)
        {
            await CommenceStartup();

            //            var builder = new ContainerBuilder();

            using (container.StartUpdate())
            {
                // Build and application dependencies
                RegisterDependencies(container);

                buildDependencies?.Invoke(container);

                //// Perform registrations and build the container.
                //var container = builder.Build();

                await BuildCoreDependencies(container);
            }

            // Set the service locator to an AutofacServiceLocator.
            //var csl = new AutofacServiceLocator(container);
            //ServiceLocator.SetLocatorProvider(() => csl);
            ServiceLocator.SetLocatorProvider(locatorProvider);

            await CompleteStartup();
        }
コード例 #4
0
ファイル: DependencyConfig.cs プロジェクト: joaofx/felice
        public static void RegisterDependencies()
        {
            Container = new Container(cfg =>
            {
                cfg.Scan(scan =>
                {
                    scan.AssembliesFromApplicationBaseDirectory(
                        assembly => assembly.FullName.EndsWith(".Tests") == false);
                    scan.LookForRegistries();

                    scan.AssemblyContainingType <ListProductQuery>();
                    scan.AssemblyContainingType <IMediator>();
                    scan.WithDefaultConventions();
                    scan.AddAllTypesOf(typeof(IRequestHandler <,>));

                    scan.ConnectImplementationsToTypesClosing(typeof(AbstractValidator <>));
                });

                cfg.For <TextWriter>().Use(Console.Out);

                cfg.For(typeof(IRequestHandler <,>)).DecorateAllWith(typeof(ValidatorHandler <,>));

                cfg.For <IDatabaseAdapter>().Use <SqLiteDatabaseAdapter>();
            });

            var serviceLocator         = new StructureMapServiceLocator(Container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            Container.Configure(cfg => cfg.For <ServiceLocatorProvider>().Use(serviceLocatorProvider));

            DependencyResolver.SetResolver(new StructureMapDependencyResolver(Container));
            Dependency.SetupContainer(Container);
        }
コード例 #5
0
        protected override IMediator BuildMediator()
        {
            _builder.RegisterSource(new ContravariantRegistrationSource());
            _builder.RegisterAssemblyTypes(typeof(IMediator).Assembly).AsImplementedInterfaces();
            _builder.Register <SingleInstanceFactory>(
                context =>
            {
                var componentContext = context.Resolve <IComponentContext>();
                return(type => componentContext.Resolve(type));
            });
            _builder.Register <MultiInstanceFactory>(
                context =>
            {
                var componentContext = context.Resolve <IComponentContext>();
                return(type => (IEnumerable <object>)componentContext.Resolve(
                           typeof(IEnumerable <>).MakeGenericType(type)));
            });

            var lazy = new Lazy <IServiceLocator>(() => new AutofacServiceLocator(_container));
            var serviceLocatorProvider = new ServiceLocatorProvider(() => lazy.Value);

            _builder.RegisterInstance(serviceLocatorProvider);

            _builder.RegisterGenericDecorator(typeof(WrapperRequestHandler <,>), typeof(IRequestHandler <,>),
                                              fromKey: _key);
#pragma warning disable 612, 618
            _builder.Update(_container.ComponentRegistry);
#pragma warning restore 612, 618
            return(serviceLocatorProvider().GetInstance <IMediator>());
        }
コード例 #6
0
        public static IContainer BootstrapApplication(HttpConfiguration config)
        {
            var container = new Container(cfg => cfg.Scan(scanner =>
            {
                scanner.Assembly(typeof(Person).Assembly);
                scanner.Assembly(typeof(BaseController).Assembly);
                scanner.AssemblyContainingType <IMediator>();
                scanner.WithDefaultConventions();
                scanner.AddAllTypesOf(typeof(IRequestHandler <,>));
                scanner.AddAllTypesOf(typeof(IAsyncRequestHandler <,>));
                scanner.AddAllTypesOf(typeof(IPostRequestHandler <,>));
                scanner.AddAllTypesOf(typeof(IAsyncPostRequestHandler <,>));
                scanner.AddAllTypesOf(typeof(INotificationHandler <>));
                scanner.AddAllTypesOf(typeof(IAsyncNotificationHandler <>));
                scanner.AddAllTypesOf <Profile>();
                scanner.AddAllTypesOf(typeof(IValidator <>));
                scanner.LookForRegistries();
            }));

            var serviceLocator = new StructureMapServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            container.Configure(cfg => cfg.For <ServiceLocatorProvider>().Use(serviceLocatorProvider));

            config.DependencyResolver = new StructureMapResolver(container);

            return(container);
        }
コード例 #7
0
        public UnityControllerFactory(IUnityContainer container)
        {
            _container = container;
            ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);

            ServiceLocator.SetLocatorProvider(sp);
        }
コード例 #8
0
        public SystemEventLogFactory(IUnityContainer container)
        {
            _container = container;
            ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);

            ServiceLocator.SetLocatorProvider(sp);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: EdsonF/MediatR
        private static IMediator BuildMediator()
        {
            var container = new Container(cfg =>
            {
                cfg.Scan(scanner =>
                {
                    scanner.AssemblyContainingType <Ping>();
                    scanner.AssemblyContainingType <IMediator>();
                    scanner.WithDefaultConventions();
                    scanner.AddAllTypesOf(typeof(IRequestHandler <,>));
                    scanner.AddAllTypesOf(typeof(IAsyncRequestHandler <,>));
                    scanner.AddAllTypesOf(typeof(INotificationHandler <>));
                    scanner.AddAllTypesOf(typeof(IAsyncNotificationHandler <>));
                });
                cfg.For <TextWriter>().Use(Console.Out);
            });

            var serviceLocator         = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            container.Configure(cfg => cfg.For <ServiceLocatorProvider>().Use(serviceLocatorProvider));

            var mediator = serviceLocator.GetInstance <IMediator>();

            return(mediator);
        }
コード例 #10
0
        public void Should_resolve_main_void_handler()
        {
            var builder = new StringBuilder();
            var writer  = new StringWriter(builder);

            var container = new Container(cfg =>
            {
                cfg.Scan(scanner =>
                {
                    scanner.TheCallingAssembly();
                    scanner.IncludeNamespaceContainingType <Ping>();
                    scanner.WithDefaultConventions();
                    scanner.AddAllTypesOf(typeof(IAsyncRequestHandler <,>));
                });
                cfg.For <TextWriter>().Use(writer);
            });


            var serviceLocator         = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            var mediator = new Mediator(serviceLocatorProvider);

            var response = mediator.SendAsync(new Ping {
                Message = "Ping"
            });

            Task.WaitAll(response);

            builder.ToString().ShouldBe("Ping Pong");
        }
コード例 #11
0
ファイル: Bootstrapper.cs プロジェクト: ChrisMissal/atxc
        public static IContainer BootstrapApplication(HttpConfiguration config)
        {
            var container = new Container(cfg => cfg.Scan(scanner =>
            {
                scanner.Assembly(typeof(Person).Assembly);
                scanner.Assembly(typeof(BaseController).Assembly);
                scanner.AssemblyContainingType<IMediator>();
                scanner.WithDefaultConventions();
                scanner.AddAllTypesOf(typeof(IRequestHandler<,>));
                scanner.AddAllTypesOf(typeof(IAsyncRequestHandler<,>));
                scanner.AddAllTypesOf(typeof(IPostRequestHandler<,>));
                scanner.AddAllTypesOf(typeof(IAsyncPostRequestHandler<,>));
                scanner.AddAllTypesOf(typeof(INotificationHandler<>));
                scanner.AddAllTypesOf(typeof(IAsyncNotificationHandler<>));
                scanner.AddAllTypesOf<Profile>();
                scanner.AddAllTypesOf(typeof(IValidator<>));
                scanner.LookForRegistries();
            }));

            var serviceLocator = new StructureMapServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            container.Configure(cfg => cfg.For<ServiceLocatorProvider>().Use(serviceLocatorProvider));

            config.DependencyResolver = new StructureMapResolver(container);

            return container;
        }
コード例 #12
0
ファイル: DependencyConfig.cs プロジェクト: joaofx/felice
        public static void RegisterDependencies()
        {
            Container = new Container(cfg =>
            {
                cfg.Scan(scan =>
                {
                    scan.AssembliesFromApplicationBaseDirectory(
                        assembly => assembly.FullName.EndsWith(".Tests") == false);
                    scan.LookForRegistries();

                    scan.AssemblyContainingType<ListProductQuery>();
                    scan.AssemblyContainingType<IMediator>();
                    scan.WithDefaultConventions();
                    scan.AddAllTypesOf(typeof (IRequestHandler<,>));

                    scan.ConnectImplementationsToTypesClosing(typeof (AbstractValidator<>));
                });

                cfg.For<TextWriter>().Use(Console.Out);

                cfg.For(typeof (IRequestHandler<,>)).DecorateAllWith(typeof (ValidatorHandler<,>));

                cfg.For<IDatabaseAdapter>().Use<SqLiteDatabaseAdapter>();
            });

            var serviceLocator = new StructureMapServiceLocator(Container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            Container.Configure(cfg => cfg.For<ServiceLocatorProvider>().Use(serviceLocatorProvider));

            DependencyResolver.SetResolver(new StructureMapDependencyResolver(Container));
            Dependency.SetupContainer(Container);
        }
コード例 #13
0
        public void Should_resolve_main_handler()
        {
            var builder = new StringBuilder();
            var writer  = new StringWriter(builder);

            var container = new Container(cfg =>
            {
                cfg.Scan(scanner =>
                {
                    scanner.TheCallingAssembly();
                    scanner.IncludeNamespaceContainingType <Ping>();
                    scanner.WithDefaultConventions();
                    scanner.AddAllTypesOf(typeof(INotificationHandler <>));
                });
                cfg.For <TextWriter>().Use(writer);
            });

            var serviceLocator         = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            var mediator = new Mediator(serviceLocatorProvider);

            mediator.Publish(new Ping {
                Message = "Ping"
            });

            var result = builder.ToString().Split(new [] { Environment.NewLine }, StringSplitOptions.None);

            result.ShouldContain("Ping Pong");
            result.ShouldContain("Ping Pung");
        }
コード例 #14
0
ファイル: ExceptionTests.cs プロジェクト: strvmarv/MediatR
        public ExceptionTests()
        {
            var container              = new Container();
            var serviceLocator         = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            _mediator = new Mediator(serviceLocatorProvider);
        }
コード例 #15
0
 public UnityControllerFactory()
 {
     _container = new UnityContainer();
     UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
     section.Configure(_container, "defaultContainer");
     ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);
     ServiceLocator.SetLocatorProvider(sp);
 }
コード例 #16
0
        /// <summary>
        /// The begin scope.
        /// </summary>
        /// <returns>
        /// The System.Web.Http.Dependencies.IDependencyScope.
        /// </returns>
        public IDependencyScope BeginScope()
        {
            var resolver = new StructureMapWebApiDependencyResolver(CurrentNestedContainer);

            ServiceLocatorProvider provider = () => resolver;

            CurrentNestedContainer.Configure(cfg => cfg.For <ServiceLocatorProvider>().Use(provider));

            return(resolver);
        }
コード例 #17
0
        public UnityControllerFactory()
        {
            _container = new UnityContainer();
            UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

            section.Configure(_container, "defaultContainer");
            ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);

            ServiceLocator.SetLocatorProvider(sp);
        }
コード例 #18
0
 public SystemEventLogFactory()
 {
     _container = new UnityContainer();
     UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
     section.Configure(_container, "defaultContainer");
     SystemEventLogService = _container.Resolve<ISystemEventLogService>() as SystemEventLogService;
     ExceptionalLogService = _container.Resolve<IExceptionalLogService>() as ExceptionalLogService;
     ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);
     ServiceLocator.SetLocatorProvider(sp);
 }
コード例 #19
0
        public SystemEventLogFactory()
        {
            _container = new UnityContainer();
            UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

            section.Configure(_container, "defaultContainer");
            SystemEventLogService = _container.Resolve <ISystemEventLogService>() as SystemEventLogService;
            ExceptionalLogService = _container.Resolve <IExceptionalLogService>() as ExceptionalLogService;
            ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);

            ServiceLocator.SetLocatorProvider(sp);
        }
コード例 #20
0
        protected override void ConfigureApplicationContainer(IWindsorContainer container)
        {
            container.Register(Classes.FromAssemblyContaining<IMediator>().Pick().WithServiceAllInterfaces());
            container.Register(Classes.FromAssemblyContaining<MyRequestHandler>().BasedOn(typeof(MediatR.IRequestHandler<,>)).Unless(x => x == typeof(SampleFileRequestHandler)).WithServiceAllInterfaces().LifestyleScoped<NancyPerWebRequestScopeAccessor>());
            container.Register(Component.For<IRequestHandler<SampleFileRequest, Unit>>().ImplementedBy<SampleFileRequestHandler>().LifestyleTransient());
            container.Register(Classes.FromAssemblyContaining<MyRequestHandler>().BasedOn(typeof(MediatR.IAsyncRequestHandler<,>)).WithServiceAllInterfaces().LifestyleScoped<NancyPerWebRequestScopeAccessor>());

            container.Register(Component.For<RequestTypeProvider>().LifestyleSingleton());

            var serviceLocator = new WindsorServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            container.Register(Component.For<ServiceLocatorProvider>().Instance(serviceLocatorProvider));
        }
コード例 #21
0
 public void Init(HttpApplication context)
 {
     context.BeginRequest += (sender, e) =>
     {
         StructuremapMvc.StructureMapDependencyScope.CreateNestedContainer();
         var serviceLocatorProvider = new ServiceLocatorProvider(() => StructuremapMvc.StructureMapDependencyScope);
         StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer.Configure(cfg => cfg.For <ServiceLocatorProvider>().Use(serviceLocatorProvider));
     };
     context.EndRequest += (sender, e) => {
         HttpContextLifecycle.DisposeAndClearAll();
         StructuremapMvc.StructureMapDependencyScope.DisposeNestedContainer();
     };
 }
コード例 #22
0
ファイル: App.xaml.cs プロジェクト: AndreiLucaci/sebicu
        public App()
        {
            var unityContainer = new UnityContainer();

            unityContainer
            .ConfigureWithDbContext()
            .ConfigureWithRepository();

            var unityServiceLocator = new UnityServiceLocator(unityContainer);
            var serviceLocator      = new ServiceLocatorProvider(() => unityServiceLocator);

            ServiceLocator.SetLocatorProvider(serviceLocator);
        }
コード例 #23
0
        /// <summary>
        /// Sets the container delegate, the delegate is invoked each time <seealso cref="GetContainer"/> is called.
        /// </summary>
        /// <param name="provider">The delegate which returns the container object.</param>
        internal static void SetLocator(ServiceLocatorProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            _serviceLocator = provider.Invoke();

            if (_serviceLocator == null)
            {
                throw new ArgumentException(LogResources.ServiceLocatorProviderDelegate_NullReturn, "provider");
            }
        }
コード例 #24
0
        public ServiceLocatorScope(IServiceLocator temporaryServiceLocator)
        {
            try
            {
                var previousLocator = ServiceLocator.Current;
                _previousLocatorProvider = () => previousLocator;
            }
            catch (NullReferenceException)
            {
                _previousLocatorProvider = null;
            }

            ServiceLocator.SetLocatorProvider(() => temporaryServiceLocator);
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: BredStik/MediatR
        private static IMediator BuildMediator()
        {
            var container = new UnityContainer();
            container.RegisterTypes(AllClasses.FromAssemblies(typeof (Ping).Assembly), WithMappings.FromAllInterfaces);
            container.RegisterTypes(AllClasses.FromAssemblies(typeof (IMediator).Assembly), WithMappings.FromAllInterfaces);
            container.RegisterInstance(Console.Out);

            var serviceLocator = new UnityServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            container.RegisterInstance(serviceLocatorProvider);

            var mediator = container.Resolve<IMediator>();

            return mediator;
        }
コード例 #26
0
ファイル: Startup.cs プロジェクト: geleems/JsonRpcMediator
    private static IContainer RegisterIoc()
    {
        var container = new Container(cfg => cfg.Scan(scan =>
        {
            scan.TheCallingAssembly();
            scan.LookForRegistries();
        }));

        var serviceLocator         = new StructureMapServiceLocator(container);
        var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

        container.Configure(cfg => cfg.For <ServiceLocatorProvider>().Use(serviceLocatorProvider));

        return(container);
    }
コード例 #27
0
ファイル: Program.cs プロジェクト: BredStik/MediatR
        private static IMediator BuildMediator()
        {
            var container = new WindsorContainer();
            container.Register(Classes.FromAssemblyContaining<IMediator>().Pick().WithServiceAllInterfaces());
            container.Register(Classes.FromAssemblyContaining<Ping>().Pick().WithServiceAllInterfaces());
            container.Register(Component.For<TextWriter>().Instance(Console.Out));
            container.Kernel.AddHandlersFilter(new ContravariantFilter());

            var serviceLocator = new WindsorServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            container.Register(Component.For<ServiceLocatorProvider>().Instance(serviceLocatorProvider));

            var mediator = container.Resolve<IMediator>();

            return mediator;
        }
コード例 #28
0
        public Bootstrapper(AbstractBootstrapperSettings settings)
        {
            Container = new Container(cfg =>
            {
                cfg.AddRegistry(new MediatorRegistry());
                cfg.AddRegistry(new PersistenceRegistry(settings));
            });

            var serviceLocationProvider = new ServiceLocatorProvider(
                () => new StructureMapServiceLocator(Container));

            ServiceLocator.SetLocatorProvider(serviceLocationProvider);

            string whatdidiscan = Container.WhatDidIScan();
            string whatdoihave  = Container.WhatDoIHave();
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: BredStik/MediatR
        private static IMediator BuildMediator()
        {
            var builder = new ContainerBuilder();
            builder.RegisterSource(new ContravariantRegistrationSource());
            builder.RegisterAssemblyTypes(typeof (IMediator).Assembly).AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(typeof (Ping).Assembly).AsImplementedInterfaces();
            builder.RegisterInstance(Console.Out).As<TextWriter>();

            var lazy = new Lazy<IServiceLocator>(() => new AutofacServiceLocator(builder.Build()));
            var serviceLocatorProvider = new ServiceLocatorProvider(() => lazy.Value);
            builder.RegisterInstance(serviceLocatorProvider);
            
            var mediator = serviceLocatorProvider().GetInstance<IMediator>();

            return mediator;
        }
コード例 #30
0
ファイル: Program.cs プロジェクト: jej666/MediatR
        private static IMediator BuildMediator()
        {
            var container = new UnityContainer();

            container.RegisterTypes(AllClasses.FromAssemblies(typeof(IMediator).Assembly), WithMappings.FromAllInterfaces);
            container.RegisterTypes(AllClasses.FromAssemblies(typeof(Ping).Assembly), WithMappings.FromAllInterfaces, GetName, GetLifetimeManager);
            container.RegisterInstance(Console.Out);

            var serviceLocator         = new UnityServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            container.RegisterInstance(serviceLocatorProvider);

            var mediator = container.Resolve <IMediator>();

            return(mediator);
        }
コード例 #31
0
ファイル: Program.cs プロジェクト: EdsonF/MediatR
        private static IMediator BuildMediator()
        {
            var builder = new ContainerBuilder();

            builder.RegisterSource(new ContravariantRegistrationSource());
            builder.RegisterAssemblyTypes(typeof(IMediator).Assembly).AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(typeof(Ping).Assembly).AsImplementedInterfaces();
            builder.RegisterInstance(Console.Out).As <TextWriter>();

            var lazy = new Lazy <IServiceLocator>(() => new AutofacServiceLocator(builder.Build()));
            var serviceLocatorProvider = new ServiceLocatorProvider(() => lazy.Value);

            builder.RegisterInstance(serviceLocatorProvider);

            var mediator = serviceLocatorProvider().GetInstance <IMediator>();

            return(mediator);
        }
コード例 #32
0
ファイル: OAuthService.cs プロジェクト: yhtsnda/oauth-dot-net
 /// <summary>
 /// Creates an OAuthService using defaults for most parameters, loading components
 /// from the service locator provided by the supplied provider.
 /// </summary>
 /// <remarks>
 /// <para>The OAuthService created will have the following defaults:</para>
 /// <list type="table">
 ///     <listheader>
 ///         <term>Property</term>
 ///         <description>Value</description>
 ///     </listheader>
 ///     <item>
 ///         <term>HttpMethod</term>
 ///         <description><c>"POST"</c></description>
 ///     </item>
 ///     <item>
 ///         <term>UseAuthorizationHeader</term>
 ///         <description><c>true</c></description>
 ///     </item>
 ///     <item>
 ///         <term>Realm</term>
 ///         <description><c>null</c></description>
 ///     </item>
 ///     <item>
 ///         <term>SignatureMethod</term>
 ///         <description><c>"HMAC-SHA1"</c></description>
 ///     </item>
 ///     <item>
 ///         <term>OAuthVersion</term>
 ///         <description><c>"1.0"</c></description>
 ///     </item>
 /// </list>
 /// </remarks>
 /// <param name="requestTokenEndPoint">EndPoint for obtaining request tokens</param>
 /// <param name="authorizationUrl">URL to send users to for authorization</param>
 /// <param name="accessTokenEndPoint">EndPoint for obtaining access tokens</param>
 /// <param name="consumer">Consumer credentials</param>
 /// <param name="serviceLocatorProvider">Service locator provider which provides a service locator for components</param>
 /// <returns>An OAuthService</returns>
 public static OAuthService Create(
     EndPoint requestTokenEndPoint,
     Uri authorizationUrl,
     EndPoint accessTokenEndPoint,
     IConsumer consumer,
     ServiceLocatorProvider serviceLocatorProvider)
 {
     return(OAuthService.Create(
                requestTokenEndPoint,
                authorizationUrl,
                accessTokenEndPoint,
                true,
                null,
                "HMAC-SHA1",
                Constants.Version1_0,
                consumer,
                serviceLocatorProvider));
 }
コード例 #33
0
        private static IMediator BuildMediator()
        {
            var container = new WindsorContainer();

            container.Register(Classes.FromAssemblyContaining <IMediator>().Pick().WithServiceAllInterfaces());
            container.Register(Classes.FromAssemblyContaining <Ping>().Pick().WithServiceAllInterfaces());
            container.Register(Component.For <TextWriter>().Instance(Console.Out));
            container.Kernel.AddHandlersFilter(new ContravariantFilter());

            var serviceLocator         = new WindsorServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            container.Register(Component.For <ServiceLocatorProvider>().Instance(serviceLocatorProvider));

            var mediator = container.Resolve <IMediator>();

            return(mediator);
        }
コード例 #34
0
ファイル: Program.cs プロジェクト: BredStik/MediatR
        private static IMediator BuildMediator()
        {
            var kernel = new StandardKernel();
            kernel.Components.Add<IBindingResolver, ContravariantBindingResolver>();
            kernel.Bind(scan => scan.FromAssemblyContaining<IMediator>().SelectAllClasses().BindDefaultInterface());
            kernel.Bind(scan => scan.FromAssemblyContaining<Ping>().SelectAllClasses().BindAllInterfaces());
            kernel.Bind<TextWriter>().ToConstant(Console.Out);

            var serviceLocator = new NinjectServiceLocator(kernel);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            kernel.Bind<ServiceLocatorProvider>().ToConstant(serviceLocatorProvider);

            var handlers = kernel.GetAll<INotificationHandler<Pinged>>();

            var mediator = serviceLocator.GetInstance<IMediator>();

            return mediator;
        }
コード例 #35
0
        public static void Configure()
        {
            IContainer container = IoC.Initialize();

            StructureMapResolver = new StructureMapDependencyResolver(container);
            DependencyResolver.SetResolver(StructureMapResolver);

            //# Add our custom httpmodule to the ASPNET pipeline.
            DynamicModuleUtility.RegisterModule(typeof(StructureMapScopeModule));

            ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());

            //# Initialize Common Service Locator.
            var serviceLocatorProvider = new ServiceLocatorProvider(() => StructureMapResolver);

            container.Configure(cfg => cfg.For <ServiceLocatorProvider>().Use(serviceLocatorProvider));

            ServiceLocator.SetLocatorProvider(serviceLocatorProvider);
        }
コード例 #36
0
        private static IMediator BuildMediator()
        {
            var kernel = new StandardKernel();

            kernel.Components.Add <IBindingResolver, ContravariantBindingResolver>();
            kernel.Bind(scan => scan.FromAssemblyContaining <IMediator>().SelectAllClasses().BindDefaultInterface());
            kernel.Bind(scan => scan.FromAssemblyContaining <Ping>().SelectAllClasses().BindAllInterfaces());
            kernel.Bind <TextWriter>().ToConstant(Console.Out);

            var serviceLocator         = new NinjectServiceLocator(kernel);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            kernel.Bind <ServiceLocatorProvider>().ToConstant(serviceLocatorProvider);

            var handlers = kernel.GetAll <INotificationHandler <Pinged> >();

            var mediator = serviceLocator.GetInstance <IMediator>();

            return(mediator);
        }
コード例 #37
0
        protected override IMediator BuildMediator()
        {
            _builder.RegisterSource(new ContravariantRegistrationSource());
            _builder.RegisterAssemblyTypes(typeof(IMediator).Assembly).AsImplementedInterfaces();

            var lazy = new Lazy<IServiceLocator>(() => new AutofacServiceLocator(_container));
            var serviceLocatorProvider = new ServiceLocatorProvider(() => lazy.Value);

            _builder.RegisterInstance(serviceLocatorProvider);

            _builder.RegisterGenericDecorator(typeof(WrapperRequestHandler<,>), typeof(IRequestHandler<,>),
                fromKey: _key);

            _builder.RegisterGenericDecorator(typeof(AsyncWrapperRequestHandler<,>), typeof(IAsyncRequestHandler<,>),
                fromKey: _asyncKey);

            _builder.Update(_container.ComponentRegistry);

            return serviceLocatorProvider().GetInstance<IMediator>();
        }
コード例 #38
0
        protected void Application_Start()
        {
            windsorContainer = new WindsorContainer();

            windsorContainer.Register(Classes.FromAssemblyContaining<IMediator>().Pick().WithServiceAllInterfaces());
            windsorContainer.Register(Classes.FromAssemblyContaining<MyRequestHandler>().BasedOn(typeof(MediatR.IRequestHandler<,>)).WithServiceAllInterfaces().LifestylePerWebRequest());
            windsorContainer.Register(Classes.FromAssemblyContaining<MyRequestHandler>().BasedOn(typeof(MediatR.IAsyncRequestHandler<,>)).WithServiceAllInterfaces().LifestylePerWebRequest());

            //windsorContainer.Kernel.AddHandlersFilter(new ContravariantFilter());

            windsorContainer.Register(Component.For<RequestTypeProvider>().LifestyleSingleton());

            var serviceLocator = new WindsorServiceLocator(windsorContainer);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            windsorContainer.Register(Component.For<ServiceLocatorProvider>().Instance(serviceLocatorProvider));

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(new WebApiConfig(windsorContainer).Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
コード例 #39
0
ファイル: SendTests.cs プロジェクト: strvmarv/MediatR
        public void Should_resolve_main_handler()
        {
            var container = new Container(cfg =>
                                          cfg.Scan(scanner =>
            {
                scanner.TheCallingAssembly();
                scanner.IncludeNamespaceContainingType <Ping>();
                scanner.WithDefaultConventions();
                scanner.AddAllTypesOf(typeof(IRequestHandler <,>));
            }));

            var serviceLocator         = new StructureMapServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            var mediator = new Mediator(serviceLocatorProvider);

            var response = mediator.Send(new Ping {
                Message = "Ping"
            });

            response.Message.ShouldBe("Ping Pong");
        }
コード例 #40
0
        static void Main(string[] args)
        {
            var container = new WindsorContainer();

            container.Register(Classes.FromAssemblyContaining<IMediator>().Pick().WithServiceAllInterfaces());
            container.Register(Classes.FromAssemblyContaining<MyRequestHandler>().BasedOn(typeof(MediatR.IRequestHandler<,>)).WithServiceAllInterfaces().LifestyleScoped());
            container.Register(Classes.FromAssemblyContaining<MyRequestHandler>().BasedOn(typeof(MediatR.IAsyncRequestHandler<,>)).WithServiceAllInterfaces().LifestyleScoped());

            container.Register(Component.For<RequestTypeProvider>().LifestyleSingleton());

            var serviceLocator = new WindsorServiceLocator(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            container.Register(Component.For<ServiceLocatorProvider>().Instance(serviceLocatorProvider));

            using (WebApp.Start(Settings.Default.Host, appBuilder => {
                appBuilder.Use<DependencyResolverScopeMiddleware>(container);
                new Startup(container.Resolve<IMediator>(), container.Resolve<RequestTypeProvider>()).Configuration(appBuilder);
            }))
            {
                Console.WriteLine("OWIN host currently listening at {0}", Settings.Default.Host);
                Console.ReadLine();
            }
        }
コード例 #41
0
        private static IMediator BuildMediator()
        {
            var container  = new Container();
            var assemblies = GetAssemblies().ToArray();

            container.Register <IMediator, Mediator>();
            container.RegisterManyForOpenGeneric(typeof(IRequestHandler <,>), assemblies);
            container.RegisterManyForOpenGeneric(typeof(IAsyncRequestHandler <,>), assemblies);
            container.RegisterManyForOpenGeneric(typeof(INotificationHandler <>), container.RegisterAll, assemblies);
            container.RegisterManyForOpenGeneric(typeof(IAsyncNotificationHandler <>), container.RegisterAll, assemblies);
            container.Register(() => Console.Out);

            var serviceLocator         = new SimpleInjectorServiceLocatorAdapter(container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);

            container.Register(() => serviceLocatorProvider);

            container.Verify();

            var mediator = container.GetInstance <IMediator>();

            return(mediator);
        }
コード例 #42
0
ファイル: OAuthService.cs プロジェクト: yhtsnda/oauth-dot-net
 public static OAuthService Create(
     EndPoint requestTokenEndPoint,
     Uri authorizationUrl,
     EndPoint accessTokenEndPoint,
     bool useAuthorizationHeader,
     string realm,
     string signatureMethod,
     string oauthVersion,
     IConsumer consumer,
     ServiceLocatorProvider serviceLocatorProvider)
 {
     return(new OAuthService()
     {
         ComponentLocator = serviceLocatorProvider(),
         RequestTokenEndPoint = requestTokenEndPoint,
         AuthorizationUrl = authorizationUrl,
         AccessTokenEndPoint = accessTokenEndPoint,
         UseAuthorizationHeader = useAuthorizationHeader,
         Realm = realm,
         SignatureMethod = signatureMethod,
         OAuthVersion = oauthVersion,
         Consumer = consumer
     });
 }
コード例 #43
0
 public ISchedulerFactory UseContainer(ServiceLocatorProvider serviceProvider)
 {
     ServiceLocator.SetLocatorProvider(serviceProvider);
     return this;
 }
コード例 #44
0
 /// <summary>
 /// 設定
 /// </summary>
 /// <param name="newProvider"></param>
 public static void SetLocatorProvider(ServiceLocatorProvider newProvider)
 {
     Locator = newProvider.Invoke();
 }
コード例 #45
0
 public UnityControllerFactory(IUnityContainer container)
 {
     _container = container;
     ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);
     ServiceLocator.SetLocatorProvider(sp);
 }
コード例 #46
0
 public Resolver(ServiceLocatorProvider resolver)
 {
     _resolver = resolver;
 }
コード例 #47
0
ファイル: OAuthService.cs プロジェクト: rpmcpp/oauth-dot-net
 /// <summary>
 /// Creates an OAuthService using defaults for most parameters, loading components
 /// from the service locator provided by the supplied provider.
 /// </summary>
 /// <remarks>
 /// <para>The OAuthService created will have the following defaults:</para>
 /// <list type="table">
 ///     <listheader>
 ///         <term>Property</term>    
 ///         <description>Value</description>
 ///     </listheader>
 ///     <item>
 ///         <term>HttpMethod</term>
 ///         <description><c>"POST"</c></description>
 ///     </item>
 ///     <item>
 ///         <term>UseAuthorizationHeader</term>
 ///         <description><c>true</c></description>
 ///     </item>
 ///     <item>
 ///         <term>Realm</term>
 ///         <description><c>null</c></description>
 ///     </item>
 ///     <item>
 ///         <term>OAuthVersion</term>
 ///         <description><c>"1.0"</c></description>
 ///     </item>
 /// </list>
 /// </remarks>
 /// <param name="requestTokenEndPoint">EndPoint for obtaining request tokens</param>
 /// <param name="authorizationUrl">URL to send users to for authorization</param>
 /// <param name="accessTokenEndPoint">EndPoint for obtaining access tokens</param>
 /// <param name="signatureMethod">Signature method to use</param>
 /// <param name="consumer">Consumer credentials</param>
 /// <param name="serviceLocatorProvider">Service locator provider which provides 
 /// a service locator for components</param>
 /// <returns>An OAuthService</returns>        
 public static OAuthService Create(
     EndPoint requestTokenEndPoint,
     Uri authorizationUrl,
     EndPoint accessTokenEndPoint,
     string signatureMethod,
     IConsumer consumer,
     ServiceLocatorProvider serviceLocatorProvider)
 {
     return OAuthService.Create(
         requestTokenEndPoint,
         authorizationUrl,
         accessTokenEndPoint,                
         true,
         null,
         signatureMethod,
         Constants.Version1_0,
         consumer,
         serviceLocatorProvider);
 }
コード例 #48
0
        private void ConfigureContainer()
        {
            _container = new WindsorContainer();
            _container.Register(Classes.FromAssemblyContaining<IMediator>().Pick().WithServiceAllInterfaces());

            _container.Register(Component.For<HttpClient>().UsingFactoryMethod(() => {
                var httpClient = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true });
                httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
                return httpClient;
            }).LifestyleSingleton());

            var mediatorLocation = (MediatorLocation)Enum.Parse(typeof(MediatorLocation), Settings.Default.MediatorLocation);
            var mediatorProtocol = (MediatorProtocol)Enum.Parse(typeof(MediatorProtocol), Settings.Default.MediatorProtocol);

            if (mediatorLocation == MediatorLocation.Local)
            {
                //in-proc handlers
                _container.Register(Classes.FromAssemblyContaining<MyRequestHandler>().Pick().WithServiceAllInterfaces());
            }
            else
            {
                switch(mediatorProtocol)
                {
                    case MediatorProtocol.Http:
                        //generic web api remote handler
                        _container.Register(Component.For(typeof(IRequestHandler<,>)).ImplementedBy(typeof(GenericWebApiRemoteHandler<,>)).LifestylePerWebRequest());
                        _container.Register(Component.For(typeof(IAsyncRequestHandler<,>)).ImplementedBy(typeof(AsyncGenericWebApiRemoteHandler<,>)).LifestylePerWebRequest());
                        break;
                    case MediatorProtocol.WCF:
                        _container.Kernel.AddFacility<WcfFacility>();
                        _container.Register(Component.For<IRequestHandlerService>()
                                   .AsWcfClient(new DefaultClientModel
                                   {
                                       Endpoint = WcfEndpoint.BoundTo(new NetTcpBinding() { TransferMode = TransferMode.Streamed })
                                           .At(Settings.Default.BackEndServiceUri)
                                   }).LifestylePerWebRequest());
                        //wcf remote handler
                        _container.Register(Component.For(typeof(IRequestHandler<,>)).ImplementedBy(typeof(GenericWcfRemoteHandler<,>)).LifestylePerWebRequest());
                        _container.Register(Component.For(typeof(IAsyncRequestHandler<,>)).ImplementedBy(typeof(AsyncGenericWcfRemoteHandler<,>)).LifestylePerWebRequest());
                        break;
                }
            }

            _container.Kernel.AddHandlersFilter(new ContravariantFilter());

            var serviceLocator = new WindsorServiceLocator(_container);
            var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
            _container.Register(Component.For<ServiceLocatorProvider>().Instance(serviceLocatorProvider));

            //BootstrapControllers
            _container.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestyleTransient());
        }
コード例 #49
0
		/// <summary>
		/// Set the delegate that is used to retrieve the current container.
		/// 
		/// </summary>
		/// <param name="newProvider">Delegate that, when called, will return
		///             the current ambient container.</param>
		public static void SetLocatorProvider(ServiceLocatorProvider newProvider)
		{
			_currentProvider = newProvider;
		}
コード例 #50
0
ファイル: OAuthService.cs プロジェクト: rpmcpp/oauth-dot-net
 public static OAuthService Create(
    EndPoint requestTokenEndPoint,
    Uri authorizationUrl,
    EndPoint accessTokenEndPoint,           
    bool useAuthorizationHeader,
    string realm,
    string signatureMethod,
    string oauthVersion,
    IConsumer consumer,
    ServiceLocatorProvider serviceLocatorProvider)
 {
     return new OAuthService()
     {
         ComponentLocator = serviceLocatorProvider(),
         RequestTokenEndPoint = requestTokenEndPoint,
         AuthorizationUrl = authorizationUrl,
         AccessTokenEndPoint = accessTokenEndPoint,
         UseAuthorizationHeader = useAuthorizationHeader,
         Realm = realm,
         SignatureMethod = signatureMethod,
         OAuthVersion = oauthVersion,
         Consumer = consumer
     };
 }
コード例 #51
0
 public UnityConnectionDependencyResolver(IUnityContainer container)
 {
     _container = container;
     ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);
     ServiceLocator.SetLocatorProvider(sp);
 }
コード例 #52
0
 public SystemEventLogFactory(IUnityContainer container)
 {
     _container = container;
     ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator);
     ServiceLocator.SetLocatorProvider(sp);
 }
コード例 #53
0
 /// <summary>
 /// Load your modules or register your services here!
 /// </summary>
 /// <param name="kernel">The kernel.</param>
 private static void RegisterServices(IKernel kernel)
 {
     kernel.Components.Add<IBindingResolver, ContravariantBindingResolver>();
     kernel.Bind(scan => scan.FromAssemblyContaining<IMediator>().SelectAllClasses().BindDefaultInterface());
     kernel.Bind(scan => scan.FromAssemblyContaining<MoviesQuery>().SelectAllClasses().BindAllInterfaces());
     var serviceLocator = new NinjectServiceLocator(kernel);
     var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator);
     kernel.Bind<ServiceLocatorProvider>().ToConstant(serviceLocatorProvider);
 }