public PoolService(IScopeFactory scopeFactory, int capacity, string?name) : base ( capacity, // // Ez itt trukkos mert: // 1) "injector" by design nem szalbiztos viszont ez a metodus lehet hivva paralell // 2) Minden egyes legyartott elemnek sajat scope kell (az egyes elemek kulon szalakban lehetnek hasznalva) // 3) Letrehozaskor a mar meglevo grafot boviteni kell // () => scopeFactory // // A letrehozott injector elettartamat PoolService deklaralo kontenere kezeli // .CreateScope(new Dictionary <string, object> { [PooledLifetime.POOL_SCOPE] = true }) // // A referenciat magat adjuk vissza, hogy azt fuggosegkent menteni lehessen a // hivo scope-jaban. // .GetReference(typeof(TInterface), name), suppressItemDispose: true ) { }
protected BaseViewModel(IScopeFactory scopeFactory = null) { if (scopeFactory != null) { _scope = scopeFactory.CreateScope(); } _logger = _scope?.Resolve <ILoggerFactory>()?.CreateLogger(GetType().Name) ?? new LoggerFactory().CreateLogger(GetType().Name); CoreDispatcher.AddHandlerToDispatcher(this); }
/// <summary> /// Create a new builder for building configuration. /// </summary> public DispatcherConfigurationBuilder(IScopeFactory scopeFactory = null) { _singleEventConfigs = new List <SingleEventTypeConfiguration>(); _multipleEventConfigs = new List <MultipleEventTypeConfiguration>(); _singleCommandConfigs = new List <SingleCommandTypeConfiguration>(); _multipleCommandConfigs = new List <MultipleCommandTypeConfiguration>(); if (scopeFactory != null) { _scope = scopeFactory.CreateScope(); } }
/// <summary> /// Create a new dispatcher instance. /// </summary> /// <param name="configuration">Dispatcher configuration.</param> /// <param name="scopeFactory">Factory of DI scope.</param> public BaseDispatcher(DispatcherConfiguration configuration, IScopeFactory scopeFactory = null) { s_Config = configuration ?? DispatcherConfiguration.Current; if (scopeFactory != null) { s_PrivateScope = scopeFactory.CreateScope(); } s_Logger = s_Scope?.Resolve <ILoggerFactory>()?.CreateLogger <BaseDispatcher>() ?? new LoggerFactory().CreateLogger <BaseDispatcher>(); }
internal InMemoryEventBus(InMemoryEventBusConfiguration configuration = null, IScopeFactory scopeFactory = null) { if (scopeFactory != null) { _scope = scopeFactory.CreateScope(); } _logger = _scope?.Resolve <ILoggerFactory>()?.CreateLogger <InMemoryEventBus>() ?? new LoggerFactory().CreateLogger <InMemoryEventBus>(); _handlers_HandleMethods = new Dictionary <Type, MethodInfo>(); _config = configuration ?? InMemoryEventBusConfiguration.Default; }
internal InMemoryCommandBus(InMemoryCommandBusConfiguration configuration = null, IScopeFactory scopeFactory = null) { if (scopeFactory != null) { _scope = scopeFactory.CreateScope(); } _logger = _scope?.Resolve <ILoggerFactory>()?.CreateLogger <InMemoryCommandBus>() ?? new LoggerFactory().CreateLogger <InMemoryCommandBus>(); _config = configuration ?? InMemoryCommandBusConfiguration.Default; }
private async Task Invoke(RequestMessage message, CancellationToken cancellationToken) { using var trace = tracing.StartTrace(message.RequestDetails.TraceHeader); tracing.AddAnnotation("event", "rest-call"); using var transaction = transactionFactory.CreateTransaction(); using var logScope = logger.BeginScope("{@requestId}", message.RequestDetails.Id); using var serviceScope = scopeFactory.CreateScope(); var invoker = serviceScope.GetService <IRequestInvoker>(); await invoker.Invoke(message, cancellationToken); transaction.Complete(); }
/// <summary> /// Initializes a new instance of the <see cref="Scoped{T}"/>. /// </summary> /// <param name="scopeFactory"> A factory for creating scopes. </param> public Scoped(IScopeFactory scopeFactory) { if (scopeFactory == null) { throw new ArgumentNullException(nameof(scopeFactory)); } if (GenericScope <T> .CurrentScope != null) { throw new InvalidOperationException($"The current scope of GenericScope<{typeof(T).Name}> is not null when trying to initialize it."); } Scope = scopeFactory.CreateScope(); GenericScope <T> .CurrentScope = Scope; }
private async Task <List <IAssembly> > LoadProjects(SolutionInfo solution, IEnumerable <ProjectInfo> buildOrder, AssemblyLoadContext assemblyLoadContext, CancellationToken cancellationToken) { return(await buildOrder.ToAsyncEnumerable().AggregateAwaitAsync( new List <IAssembly>(), async(projectAssemblies, projectInfo) => { using var scope = _projectLoader.CreateScope(solution); var project = await scope.Value.LoadProjectAsync( projectInfo, assemblyLoadContext, projectAssemblies, cancellationToken); projectAssemblies.Add(project); return projectAssemblies; })); }
public async Task ShouldInvokeAllReceivedMessagesThenCompleteTransactions( RequestMessage message1, RequestMessage message2, IScope scope1, IScope scope2, IRequestInvoker invoker1, IRequestInvoker invoker2, ITransaction transaction1, ITransaction transaction2, [Frozen] ITransactionFactory transactionFactory, [Frozen] IRequestMessageRelay relay, [Frozen] IScopeFactory scopeFactory, [Target] DefaultRequestWorker worker, CancellationToken cancellationToken ) { transactionFactory.CreateTransaction().Returns(transaction1, transaction2); scope1.GetService <IRequestInvoker>().Returns(invoker1); scope2.GetService <IRequestInvoker>().Returns(invoker2); scopeFactory.CreateScope().Returns(scope1, scope2); relay.Receive(Any <CancellationToken>()).Returns(new[] { message1, message2 }); await worker.Run(cancellationToken); Received.InOrder(async() => { transactionFactory.Received().CreateTransaction(); scopeFactory.Received().CreateScope(); scope1.Received().GetService <IRequestInvoker>(); await invoker1.Received().Invoke(Is(message1), Is(cancellationToken)); transaction1.Received().Complete(); transactionFactory.Received().CreateTransaction(); scopeFactory.Received().CreateScope(); scope2.Received().GetService <IRequestInvoker>(); await invoker2.Received().Invoke(Is(message2), Is(cancellationToken)); transaction2.Received().Complete(); }); }
public CQELightServiceProvider(IScopeFactory scopeFactory) { this.scope = scopeFactory.CreateScope(); }
/// <summary> /// Begins a new scope of DIManager. /// </summary> /// <returns>New instance of scope.</returns> public static IScope BeginScope() => _scopeFactory.CreateScope();
private async void OnEventReceived(object model, BasicDeliverEventArgs args) { if (args.Body?.Any() == true && model is EventingBasicConsumer consumer) { var result = Result.Ok(); try { var dataAsStr = Encoding.UTF8.GetString(args.Body); var enveloppe = dataAsStr.FromJson <Enveloppe>(); if (enveloppe != null) { if (enveloppe.Emiter == _config.ConnectionInfos.ServiceName) { consumer.Model.BasicAck(args.DeliveryTag, false); return; } if (!string.IsNullOrWhiteSpace(enveloppe.Data) && !string.IsNullOrWhiteSpace(enveloppe.AssemblyQualifiedDataType)) { var objType = Type.GetType(enveloppe.AssemblyQualifiedDataType); if (objType != null) { var serializer = GetSerializerByContentType(args.BasicProperties?.ContentType); if (typeof(IDomainEvent).IsAssignableFrom(objType)) { var evt = serializer.DeserializeEvent(enveloppe.Data, objType); try { _config.EventCustomCallback?.Invoke(evt); } catch (Exception e) { _logger.LogError( $"Error when executing custom callback for event {objType.AssemblyQualifiedName}. {e}"); result = Result.Fail(); } if (scopeFactory != null) { using (var scope = scopeFactory.CreateScope()) { var bus = scope.Resolve <InMemoryEventBus>(); if (_config.DispatchInMemory && bus != null) { result = await bus.PublishEventAsync(evt).ConfigureAwait(false); } } } } else if (typeof(ICommand).IsAssignableFrom(objType)) { var cmd = serializer.DeserializeCommand(enveloppe.Data, objType); try { _config.CommandCustomCallback?.Invoke(cmd); } catch (Exception e) { _logger.LogError( $"Error when executing custom callback for command {objType.AssemblyQualifiedName}. {e}"); result = Result.Fail(); } using (var scope = scopeFactory.CreateScope()) { var bus = scope.Resolve <InMemoryCommandBus>(); if (_config.DispatchInMemory && bus != null) { result = await bus.DispatchAsync(cmd).ConfigureAwait(false); } } } } } } } catch (Exception exc) { _logger.LogErrorMultilines("RabbitMQServer : Error when treating event.", exc.ToString()); result = Result.Fail(); } if (!result && _config.AckStrategy == AckStrategy.AckOnSucces) { consumer.Model.BasicReject(args.DeliveryTag, false); } else { consumer.Model.BasicAck(args.DeliveryTag, false); } } else { _logger.LogWarning("RabbitMQServer : Empty message received or event fired by bad model !"); } }