コード例 #1
0
        private async Task Poll(IContainerRegistrar registrar, CancellationToken token)
        {
            using (var transaction = await registrar.BeginTransaction())
            {
                var desiredContainers = await _client.GetRunningContainerServices(token);

                var desiredContainerIds = desiredContainers.Select(x => x.ContainerId).ToList();
                var currentContainers   = transaction.GetContainers();

                var newContainers = from containerId in desiredContainerIds.Except(currentContainers).Distinct()
                                    from containerService in desiredContainers.Where(x => x.ContainerId == containerId)
                                    select containerService;
                var updatedContainers = from c in desiredContainers
                                        from v in currentContainers.Where(x => c.ContainerId == x)
                                        select c;
                var extraContainers = currentContainers.Except(desiredContainerIds).Distinct();

                foreach (var service in newContainers)
                {
                    Logger.Info($"Discovered services [{service.ServiceName}] for container [{service.ContainerId.ToShortContainerName()}].");
                    transaction.AddContainerService(service);
                }

                foreach (var service in updatedContainers)
                {
                    transaction.UpdateContainerService(service);
                }

                foreach (var containerId in extraContainers)
                {
                    Logger.Info($"Container [{containerId.ToShortContainerName()}] was removed.");
                    transaction.DeleteContainer(containerId);
                }
            }
        }
コード例 #2
0
        public async Task Monitor(IContainerRegistrar registrar, CancellationToken token)
        {
            registrar.ContainerServiceCreated += RegistrarOnContainerServiceCreated;
            registrar.ContainerDeleted        += RegistrarOnContainerDeleted;

            await _scheduler.ScheduleRecurring <ServiceRegistrationAgent>(() => MaintenanceLoop(registrar, token), token);
        }
コード例 #3
0
 public void RegisterTypes(IContainerRegistrar services)
 {
     services.AddSingleton <ICommandHandler, OutputCommandHandler>();
     services.AddSingleton <ICommandHandler, OutputAssemblyInfoCommandHandler>();
     services.AddSingleton <ICommandHandler, OutputProjectCommandHandler>();
     services.AddSingleton <ICommandHandler, OutputWixCommandHandler>();
 }
コード例 #4
0
ファイル: Mission.cs プロジェクト: Silvenga/Emissary
 public Mission(IContainerRegistrar registrar, Lazy <List <IAgent> > lazyAgents, JobScheduler scheduler, EmissaryConfiguration configuration)
 {
     _registrar     = registrar;
     _lazyAgents    = lazyAgents;
     _scheduler     = scheduler;
     _configuration = configuration;
 }
コード例 #5
0
        private async Task HandleEvents(IContainerRegistrar registrar, CancellationToken token)
        {
            foreach (var progress in _yieldingProgress.GetEnumerable(token))
            {
                using (var transaction = await registrar.BeginTransaction())
                {
                    //Logger.Info($"Handing new event {progress.Status} for container {progress.ContainerId}.");

                    // attach, commit, copy, create, destroy, detach, die, exec_create, exec_detach, exec_start, export, health_status, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update

                    switch (progress.Status)
                    {
                    case "update":
                    case "start":
                    case "restart":
                        var containerServices = await _client.GetContainerServicesById(progress.ContainerId, token);

                        foreach (var containerService in containerServices)
                        {
                            ConsiderAddedService(transaction, containerService);
                        }
                        break;

                    case "destroy":
                    case "die":
                    case "stop":
                    case "kill":
                        ConsiderRemovedContainer(transaction, progress.ContainerId);
                        break;
                    }
                }
            }
        }
コード例 #6
0
 public ContainerBuilderRiderConfigurator(ContainerBuilder builder, IContainerRegistrar registrar, HashSet <Type> riderTypes)
     : base(registrar)
 {
     Builder       = builder;
     _riderTypes   = riderTypes;
     Registrations = new RegistrationCache <object>();
 }
コード例 #7
0
        protected ServiceCollectionConfigurator(IServiceCollection collection, IContainerRegistrar registrar)
            : base(registrar)
        {
            Collection = collection;

            AddMassTransitComponents(collection);
        }
コード例 #8
0
 public ActivityRegistrationConfigurator(IRegistrationConfigurator configurator, IActivityRegistration registration,
                                         IContainerRegistrar registrar)
 {
     _configurator = configurator;
     _registration = registration;
     _registrar    = registrar;
 }
コード例 #9
0
        private async Task MaintenanceLoop(IContainerRegistrar registrar, CancellationToken token)
        {
            using (var transaction = await registrar.BeginTransaction())
            {
                var desiredServices = transaction.GetAllContainerServices();
                var consulServices  = await _client.GetRegisteredServicesAndChecks(token);

                var checks = (from desiredService in desiredServices
                              from consulService in consulServices.Where(x => x.ContainerId == desiredService.ContainerId).DefaultIfEmpty()
                              let status = ""
                                           + $"Container: {desiredService.ContainerId.ToShortContainerName()}\n"
                                           + $"    Image: {desiredService.Image}\n"
                                           + $" Creation: {desiredService.ContainerCreationOn}\n"
                                           + $"    State: {desiredService.ContainerState}\n"
                                           + $"   Status: {desiredService.ContainerStatus}"
                                           select new
                {
                    desiredService.ContainerId,
                    Status = status,
                    consulService?.CheckId,
                    Missing = consulService == null
                }).ToList();

                foreach (var check in checks.Where(x => x.Missing))
                {
                    Logger.Warn($"Container [{check.ContainerId.ToShortContainerName()}] disappeared from consul, assuming the container was removed.");
                    transaction.DeleteContainer(check.ContainerId);
                }

                foreach (var check in checks.Where(x => !x.Missing))
                {
                    await _client.MaintainService(check.CheckId, check.Status, token);
                }
            }
        }
コード例 #10
0
 public ServiceCollectionRiderConfigurator(IServiceCollection collection, IContainerRegistrar registrar, HashSet <Type> riderTypes)
     : base(registrar)
 {
     _riderTypes   = riderTypes;
     Collection    = collection;
     Registrations = new RegistrationCache <object>();
 }
コード例 #11
0
        protected ServiceCollectionBusConfigurator(IServiceCollection collection, IContainerRegistrar registrar)
            : base(registrar)
        {
            Collection = collection;
            RiderTypes = new HashSet <Type>();

            AddMassTransitComponents(collection);
        }
コード例 #12
0
 /// <summary>
 /// Register all services
 /// </summary>
 /// <param name="registrar">Registrar used for the registration</param>
 public void Register(IContainerRegistrar registrar)
 {
     registrar.RegisterService(x => _store.OpenSession(), Lifetime.Scoped);
     registrar.RegisterConcrete<UowAdapter>(Lifetime.Scoped);
     //registrar.RegisterService(x => new UowAdapter(x.Resolve<IDocumentSession>(), _observer), Lifetime.Scoped);
     registrar.RegisterInstance(typeof (IUnitOfWorkObserver), _observerAdapter);
     registrar.RegisterInstance(typeof (IUnitOfWorkAdapter), this);
 }
コード例 #13
0
 /// <summary>
 /// Use Griffin.Container to execute the queries
 /// </summary>
 /// <param name="registrar">Your registrar</param>
 /// <param name="lifetime">The lifetime that the dispatcher should get.</param>
 public static void DispatchQueries(this IContainerRegistrar registrar, Lifetime lifetime)
 {
     if (registrar == null)
     {
         throw new ArgumentNullException("registrar");
     }
     registrar.RegisterService <Queries.IQueryDispatcher>(x => new QueryDispatcher(x), lifetime);
 }
コード例 #14
0
 public void Register(IContainerRegistrar registrar)
 {
     registrar.Register(provider =>
     {
         var bus = provider.GetRequiredService <IBus>();
         var sendEndpointProvider = provider.GetRequiredService <ISendEndpointProvider>();
         return(sendEndpointProvider.CreateAmazonSqsMessageScheduler(bus.Topology));
     });
 }
コード例 #15
0
        public RegistrationConfigurator(IContainerRegistrar containerRegistrar = null)
        {
            _containerRegistrar = containerRegistrar ?? new NullContainerRegistrar();

            _consumerConfigurations       = new ConcurrentDictionary <Type, IConsumerRegistration>();
            _sagaConfigurations           = new ConcurrentDictionary <Type, ISagaRegistration>();
            _executeActivityRegistrations = new ConcurrentDictionary <Type, IExecuteActivityRegistration>();
            _activityRegistrations        = new ConcurrentDictionary <Type, IActivityRegistration>();
        }
コード例 #16
0
 public void Register(IContainerRegistrar registrar)
 {
     registrar.Register(provider =>
     {
         var bus             = provider.GetRequiredService <IBus>();
         var publishEndpoint = provider.GetRequiredService <IPublishEndpoint>();
         return(publishEndpoint.CreateMessageScheduler(bus.Topology));
     });
 }
コード例 #17
0
        protected RegistrationConfigurator(IContainerRegistrar registrar = null)
        {
            Registrar = registrar ?? new NullContainerRegistrar();

            _consumers         = new RegistrationCache <IConsumerRegistration>();
            _sagas             = new RegistrationCache <ISagaRegistration>();
            _executeActivities = new RegistrationCache <IExecuteActivityRegistration>();
            _activities        = new RegistrationCache <IActivityRegistration>();
            _endpoints         = new RegistrationCache <IEndpointRegistration>();
        }
コード例 #18
0
        public static IContainerRegistrar RegisterModules(this IContainerRegistrar containerRegistrar,
                                                          IEnumerable <IGitVersionModule> gitVersionModules)
        {
            foreach (var gitVersionModule in gitVersionModules)
            {
                containerRegistrar.RegisterModule(gitVersionModule);
            }

            return(containerRegistrar);
        }
コード例 #19
0
        /// <summary>
        /// Builds a container using the specified registrations.
        /// </summary>
        /// <param name="registrar">Registrations to use</param>
        /// <returns>A created container.</returns>
        /// <remarks>Will analyze all registrations and create a build plan for each service</remarks>
        public IParentContainer Build(IContainerRegistrar registrar)
        {
            if (registrar == null) throw new ArgumentNullException("registrar");

            _registrar = registrar;
            GenerateBuildPlans(registrar);
            MapConcretesToServices();
            BindPlans();
            Validate();
            return new Container(_serviceMappings);
        }
コード例 #20
0
        public static void RegisterSagaStateMachines(this IContainerRegistrar registrar, params Assembly[] assemblies)
        {
            if (assemblies.Length == 0)
            {
                assemblies = AppDomain.CurrentDomain.GetAssemblies();
            }

            var types = AssemblyTypeCache.FindTypes(assemblies, x => x.HasInterface(typeof(SagaStateMachine <>))).GetAwaiter().GetResult();

            registrar.RegisterSagaStateMachines(types.FindTypes(TypeClassification.Concrete | TypeClassification.Closed).ToArray());
        }
コード例 #21
0
        public static void RegisterSagaStateMachines(this IContainerRegistrar registrar, params Type[] types)
        {
            foreach (var type in types)
            {
                if (!type.HasInterface(typeof(SagaStateMachine <>)))
                {
                    throw new ArgumentException($"The type is not a saga state machine: {TypeMetadataCache.GetShortName(type)}", nameof(types));
                }

                SagaStateMachineRegistrationCache.Register(type, registrar);
            }
        }
コード例 #22
0
        /// <summary>
        /// Builds a container using the specified registrations.
        /// </summary>
        /// <param name="registrar">Registrations to use</param>
        /// <returns>A created container.</returns>
        /// <remarks>Will analyze all registrations and create a build plan for each service</remarks>
        public IParentContainer Build(IContainerRegistrar registrar)
        {
            if (registrar == null)
            {
                throw new ArgumentNullException("registrar");
            }

            _registrar = registrar;
            GenerateBuildPlans(registrar);
            MapConcretesToServices();
            BindPlans();
            Validate();
            return(new Container(_serviceMappings));
        }
コード例 #23
0
        private async Task Cleanup(IContainerRegistrar registrar)
        {
            Logger.Info("A shutdown event has been captured, will begin cleanup logic.");

            using (var transaction = await registrar.BeginTransaction())
            {
                foreach (var containerId in transaction.GetContainers())
                {
                    Logger.Info($"Removing container [{containerId.ToShortContainerName()}].");
                    transaction.DeleteContainer(containerId);
                }
            }

            Logger.Info("Cleanup completed.");
        }
コード例 #24
0
        /// <summary>
        /// Register all controllers
        /// </summary>
        /// <param name="registrar">The registrar</param>
        /// <param name="assembly">Assembly to scan.</param>
        public static void RegisterControllers(this IContainerRegistrar registrar, Assembly assembly)
        {
            var controllerType = typeof(IController);

            foreach (var type in assembly.GetTypes().Where(controllerType.IsAssignableFrom))
            {
                // no public constructors. A base class?
                if (type.GetConstructors().Length == 0 || type.IsAbstract)
                {
                    continue;
                }

                registrar.RegisterType(type, type, Lifetime.Transient);
            }
        }
コード例 #25
0
        /// <summary>
        /// Go through all registrations and lookup their dependencies.
        /// </summary>
        /// <param name="registrar"></param>
        private void GenerateBuildPlans(IContainerRegistrar registrar)
        {
            foreach (var registration in registrar.Registrations)
            {
                var strategy = registration.InstanceStrategy ?? CreateStrategy(registration);

                if (!strategy.IsInstanceFactory)
                {
                    var buildPlan = registration.ConcreteType.IsGenericType
                        ? new GenericBuildPlan(registration.ConcreteType, registration.Services, registration.Lifetime, strategy)
                        : new ConcreteBuildPlan(registration.ConcreteType, registration.Services, registration.Lifetime, strategy);

                    ConstructorInfo constructor;
                    var             error = TryGetConstructor(registration.ConcreteType, out constructor);
                    if (error != null)
                    {
                        throw new ConcreteDependencyMissingException(registration.ConcreteType, error);
                    }

                    buildPlan.SetConstructor(constructor);
                    if (_buildPlans.ContainsKey(registration.ConcreteType))
                    {
                        throw new InvalidOperationException(
                                  $"Concrete \'{registration.ConcreteType}\' has already been registered.");
                    }

                    _buildPlans.Add(registration.ConcreteType, buildPlan);
                }
                else
                {
                    foreach (var service in registration.Services)
                    {
                        IList <IBuildPlan> buildPlans;
                        if (!_serviceMappings.TryGetValue(service, out buildPlans))
                        {
                            buildPlans = new List <IBuildPlan>();
                            _serviceMappings.Add(service, buildPlans);
                        }

                        var bp = new ExternalBuildPlan(registration.Services, registration.Lifetime, strategy);
                        buildPlans.Add(bp);
                    }
                }
            }
        }
コード例 #26
0
        /// <summary>
        /// Scan specified assembly after WebApi controllers.
        /// </summary>
        /// <param name="registrar">Container registrar to register the controllers in.</param>
        /// <param name="assembly">Assembly to scan</param>
        /// <example>
        /// <code>
        /// registrar.RegisterApiControllers(typeof(WebApiApplication).Assembly);
        /// </code>
        /// </example>
        public static void RegisterApiControllers(this IContainerRegistrar registrar, Assembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            var controllers =
                assembly.GetTypes().Where(
                    x => typeof(ApiController).IsAssignableFrom(x));

            foreach (var controller in controllers)
            {
                // no public constructors. A base class?
                if (controller.GetConstructors().Length == 0 || controller.IsAbstract)
                {
                    continue;
                }

                registrar.RegisterConcrete(controller, Lifetime.Transient);
            }
        }
コード例 #27
0
        /// <summary>
        /// Go through all registrations and lookup their dependencies.
        /// </summary>
        /// <param name="registrar"></param>
        private void GenerateBuildPlans(IContainerRegistrar registrar)
        {
            foreach (var registration in registrar.Registrations)
            {
                var strategy = registration.InstanceStrategy ?? CreateStrategy(registration);

                if (!strategy.IsInstanceFactory)
                {
                    var buildPlan = registration.ConcreteType.IsGenericType
                        ? new GenericBuildPlan(registration.ConcreteType, registration.Services, registration.Lifetime, strategy)
                        : new ConcreteBuildPlan(registration.ConcreteType, registration.Services, registration.Lifetime, strategy);

                    ConstructorInfo constructor;
                    var error = TryGetConstructor(registration.ConcreteType, out constructor);
                    if (error != null)
                        throw new ConcreteDependencyMissingException(registration.ConcreteType, error);

                    buildPlan.SetConstructor(constructor);
                    _buildPlans.Add(registration.ConcreteType, buildPlan);
                }
                else
                {
                    foreach (var service in registration.Services)
                    {
                        IList<IBuildPlan> buildPlans;
                        if (!_serviceMappings.TryGetValue(service, out buildPlans))
                        {
                            buildPlans = new List<IBuildPlan>();
                            _serviceMappings.Add(service, buildPlans);
                        }

                        var bp = new ExternalBuildPlan(registration.Services, registration.Lifetime, strategy);
                        buildPlans.Add(bp);
                    }

                }
            }
        }
コード例 #28
0
 /// <summary>
 /// Register the class in the container
 /// </summary>
 /// <param name="concrete">Class which has been decorated with the attribute.</param>
 /// <param name="registrar">The container registrar.</param>
 public void Register(Type concrete, IContainerRegistrar registrar)
 {
     registrar.RegisterConcrete(concrete, Lifetime.Default);
 }
コード例 #29
0
ファイル: CommonModule.cs プロジェクト: GitTools/GitVersionV6
 public void RegisterTypes(IContainerRegistrar services)
 {
     services.AddSingleton <IService, Service>();
 }
コード例 #30
0
 public static void Register(Type sagaDefinitionType, IContainerRegistrar registrar)
 {
     GetOrAdd(sagaDefinitionType).Register(registrar);
 }
コード例 #31
0
 public void Register(IContainerRegistrar registrar)
 {
     registrar.RegisterFutureDefinition <TDefinition, TFuture>();
 }
コード例 #32
0
 public static void Register(Type futureDefinitionType, IContainerRegistrar registrar)
 {
     Cached.Instance.GetOrAdd(futureDefinitionType).Register(registrar);
 }
コード例 #33
0
 public void Register(IContainerRegistrar registrar)
 {
     registrar.RegisterConcrete<MySelf>(Lifetime.Transient);
 }
コード例 #34
0
 /// <summary>
 /// Register all services
 /// </summary>
 /// <param name="registrar">Registrar used for the registration</param>
 public void Register(IContainerRegistrar registrar)
 {
     registrar.RegisterComponents(Lifetime.Transient, typeof(SampleService).Assembly);
 }
コード例 #35
0
ファイル: CompositionRoot.cs プロジェクト: Greeley/Samples
 /// <summary>
 /// Register all services
 /// </summary>
 /// <param name="registrar">Registrar used for the registration</param>
 public void Register(IContainerRegistrar registrar)
 {
     //just register everything that has been tagged with the [Component] attribute
     registrar.RegisterComponents(Lifetime.Scoped, Assembly.GetExecutingAssembly());
 }
コード例 #36
0
 /// <summary>
 /// Register all services
 /// </summary>
 /// <param name="registrar">Registrar used for the registration</param>
 public void Register(IContainerRegistrar registrar)
 {
     registrar.RegisterComponents(Lifetime.Scoped, Assembly.GetExecutingAssembly());
 }
コード例 #37
0
 /// <summary>
 /// Register all services
 /// </summary>
 /// <param name="registrar">Registrar used for the registration</param>
 public void Register(IContainerRegistrar registrar)
 {
     //just register everything that has been tagged with the [Component] attribute
     registrar.RegisterComponents(Lifetime.Scoped, Assembly.GetExecutingAssembly());
 }
コード例 #38
0
 public SagaRegistrationConfigurator(IRegistrationConfigurator configurator, IContainerRegistrar registrar)
 {
     _configurator = configurator;
     _registrar    = registrar;
 }
コード例 #39
0
        // this is the single method defined by the LoadEventListener interface
        /*public override void OnLoad(LoadEvent theEvent, LoadType loadType)
        {
            var type = Type.GetType(theEvent.EntityClassName);

            //_fluentConfig.Mappings(m => m.FluentMappings.)
            if (null == theEvent.InstanceToLoad)
            {
                theEvent.InstanceToLoad = ServiceResolver.Current.Resolve(type);
            }
        }*/

        #region IContainerModule Members

        /// <summary>
        /// Register all services
        /// </summary>
        /// <param name="registrar">Registrar used for the registration</param>
        public void Register(IContainerRegistrar registrar)
        {
            registrar.RegisterService<ISession>(x=> _sessionFactory.OpenSession(), Lifetime.Scoped);
            registrar.RegisterService<IUnitOfWork>(x => new NhibernateUow(x.Resolve<ISession>()),
                                                   Lifetime.Scoped);
        }