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; }
public UnityConnectionDependencyResolver(IUnityContainer container) { _container = container; ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator); ServiceLocator.SetLocatorProvider(sp); }
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(); }
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); }
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>()); }
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); }
public UnityControllerFactory(IUnityContainer container) { _container = container; ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator); ServiceLocator.SetLocatorProvider(sp); }
public SystemEventLogFactory(IUnityContainer container) { _container = container; ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator); ServiceLocator.SetLocatorProvider(sp); }
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); }
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"); }
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; }
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); }
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"); }
public ExceptionTests() { var container = new Container(); var serviceLocator = new StructureMapServiceLocator(container); var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator); _mediator = new Mediator(serviceLocatorProvider); }
public UnityControllerFactory() { _container = new UnityContainer(); UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); section.Configure(_container, "defaultContainer"); ServiceLocatorProvider sp = new ServiceLocatorProvider(GetServiceLocator); ServiceLocator.SetLocatorProvider(sp); }
/// <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); }
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); }
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); }
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)); }
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(); }; }
public App() { var unityContainer = new UnityContainer(); unityContainer .ConfigureWithDbContext() .ConfigureWithRepository(); var unityServiceLocator = new UnityServiceLocator(unityContainer); var serviceLocator = new ServiceLocatorProvider(() => unityServiceLocator); ServiceLocator.SetLocatorProvider(serviceLocator); }
/// <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"); } }
public ServiceLocatorScope(IServiceLocator temporaryServiceLocator) { try { var previousLocator = ServiceLocator.Current; _previousLocatorProvider = () => previousLocator; } catch (NullReferenceException) { _previousLocatorProvider = null; } ServiceLocator.SetLocatorProvider(() => temporaryServiceLocator); }
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; }
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); }
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; }
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(); }
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; }
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); }
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); }
/// <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)); }
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); }
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; }
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); }
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); }
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>(); }
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); }
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"); }
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(); } }
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); }
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 }); }
public ISchedulerFactory UseContainer(ServiceLocatorProvider serviceProvider) { ServiceLocator.SetLocatorProvider(serviceProvider); return this; }
/// <summary> /// 設定 /// </summary> /// <param name="newProvider"></param> public static void SetLocatorProvider(ServiceLocatorProvider newProvider) { Locator = newProvider.Invoke(); }
public Resolver(ServiceLocatorProvider resolver) { _resolver = resolver; }
/// <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); }
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()); }
/// <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; }
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 }; }
/// <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); }