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); } } }
public async Task Monitor(IContainerRegistrar registrar, CancellationToken token) { registrar.ContainerServiceCreated += RegistrarOnContainerServiceCreated; registrar.ContainerDeleted += RegistrarOnContainerDeleted; await _scheduler.ScheduleRecurring <ServiceRegistrationAgent>(() => MaintenanceLoop(registrar, token), token); }
public void RegisterTypes(IContainerRegistrar services) { services.AddSingleton <ICommandHandler, OutputCommandHandler>(); services.AddSingleton <ICommandHandler, OutputAssemblyInfoCommandHandler>(); services.AddSingleton <ICommandHandler, OutputProjectCommandHandler>(); services.AddSingleton <ICommandHandler, OutputWixCommandHandler>(); }
public Mission(IContainerRegistrar registrar, Lazy <List <IAgent> > lazyAgents, JobScheduler scheduler, EmissaryConfiguration configuration) { _registrar = registrar; _lazyAgents = lazyAgents; _scheduler = scheduler; _configuration = configuration; }
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; } } } }
public ContainerBuilderRiderConfigurator(ContainerBuilder builder, IContainerRegistrar registrar, HashSet <Type> riderTypes) : base(registrar) { Builder = builder; _riderTypes = riderTypes; Registrations = new RegistrationCache <object>(); }
protected ServiceCollectionConfigurator(IServiceCollection collection, IContainerRegistrar registrar) : base(registrar) { Collection = collection; AddMassTransitComponents(collection); }
public ActivityRegistrationConfigurator(IRegistrationConfigurator configurator, IActivityRegistration registration, IContainerRegistrar registrar) { _configurator = configurator; _registration = registration; _registrar = registrar; }
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); } } }
public ServiceCollectionRiderConfigurator(IServiceCollection collection, IContainerRegistrar registrar, HashSet <Type> riderTypes) : base(registrar) { _riderTypes = riderTypes; Collection = collection; Registrations = new RegistrationCache <object>(); }
protected ServiceCollectionBusConfigurator(IServiceCollection collection, IContainerRegistrar registrar) : base(registrar) { Collection = collection; RiderTypes = new HashSet <Type>(); AddMassTransitComponents(collection); }
/// <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); }
/// <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); }
public void Register(IContainerRegistrar registrar) { registrar.Register(provider => { var bus = provider.GetRequiredService <IBus>(); var sendEndpointProvider = provider.GetRequiredService <ISendEndpointProvider>(); return(sendEndpointProvider.CreateAmazonSqsMessageScheduler(bus.Topology)); }); }
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>(); }
public void Register(IContainerRegistrar registrar) { registrar.Register(provider => { var bus = provider.GetRequiredService <IBus>(); var publishEndpoint = provider.GetRequiredService <IPublishEndpoint>(); return(publishEndpoint.CreateMessageScheduler(bus.Topology)); }); }
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>(); }
public static IContainerRegistrar RegisterModules(this IContainerRegistrar containerRegistrar, IEnumerable <IGitVersionModule> gitVersionModules) { foreach (var gitVersionModule in gitVersionModules) { containerRegistrar.RegisterModule(gitVersionModule); } return(containerRegistrar); }
/// <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); }
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()); }
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); } }
/// <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)); }
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."); }
/// <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); } }
/// <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); } } } }
/// <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); } }
/// <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); } } } }
/// <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); }
public void RegisterTypes(IContainerRegistrar services) { services.AddSingleton <IService, Service>(); }
public static void Register(Type sagaDefinitionType, IContainerRegistrar registrar) { GetOrAdd(sagaDefinitionType).Register(registrar); }
public void Register(IContainerRegistrar registrar) { registrar.RegisterFutureDefinition <TDefinition, TFuture>(); }
public static void Register(Type futureDefinitionType, IContainerRegistrar registrar) { Cached.Instance.GetOrAdd(futureDefinitionType).Register(registrar); }
public void Register(IContainerRegistrar registrar) { registrar.RegisterConcrete<MySelf>(Lifetime.Transient); }
/// <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); }
/// <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()); }
/// <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()); }
public SagaRegistrationConfigurator(IRegistrationConfigurator configurator, IContainerRegistrar registrar) { _configurator = configurator; _registrar = registrar; }
// 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); }