public LcdpServer(ILcdpPacketSerializer lcdpPacketSerializer, IListener listener, IForwarder forwarder, IResolver resolver) { this.lcdpPacketSerializer = lcdpPacketSerializer; this.listener = listener; this.forwarder = forwarder; this.messages = new ConcurrentDictionary<string, LcdpMessage>(); this.ChunkExpirationTimeMilliseconds = 5000; this.compressors = new Dictionary<byte, ICompressor>(); this.serializers = new Dictionary<byte, ISerializer>(); for(byte b = 0; b < byte.MaxValue; ++b) { ICompressor compressor = resolver.Resolve<ICompressor>(b.ToString()); if (compressor != null) { compressors[b] = compressor; } ISerializer serializer = resolver.Resolve<ISerializer>(b.ToString()); if (serializer != null) { serializers[b] = serializer; } } }
public async Task ExecuteAsync(IResolver resolver, CancellationToken cancellationToken) { var queryProcessor = resolver.Resolve<IQueryProcessor>(); var updateItineraryService = resolver.Resolve<IUpdateItineraryService>(); var commandBus = resolver.Resolve<ICommandBus>(); var routingService = resolver.Resolve<IRoutingService>(); var cargo = (await queryProcessor.ProcessAsync(new GetCargosQuery(CargoId), cancellationToken).ConfigureAwait(false)).Single(); var updatedItinerary = await updateItineraryService.UpdateItineraryAsync(cargo.Itinerary, cancellationToken).ConfigureAwait(false); if (cargo.Route.Specification().IsSatisfiedBy(updatedItinerary)) { await commandBus.PublishAsync(new CargoSetItineraryCommand(cargo.Id, updatedItinerary), cancellationToken).ConfigureAwait(false); return; } var newItineraries = await routingService.CalculateItinerariesAsync(cargo.Route, cancellationToken).ConfigureAwait(false); var newItinerary = newItineraries.FirstOrDefault(); if (newItinerary == null) { // TODO: Tell domain that a new itinerary could not be found throw DomainError.With("Could not find itinerary"); } await commandBus.PublishAsync(new CargoSetItineraryCommand(cargo.Id, newItinerary), cancellationToken).ConfigureAwait(false); }
public BaseApiController( IResolver resolver ) { Resolver = resolver; commandProcessor = new Lazy <ICommandProcessor>(Resolver.Resolve <ICommandProcessor>()); queryProcessor = new Lazy <IQueryProcessor>(Resolver.Resolve <IQueryProcessor>()); }
public static PublishCommandJob Create( ICommand command, IResolver resolver) { var commandDefinitionService = resolver.Resolve <ICommandDefinitionService>(); var jsonSerializer = resolver.Resolve <IJsonSerializer>(); return(Create(command, commandDefinitionService, jsonSerializer)); }
public object Resolve(Type type, object argumentsAsAnonymousType) { var resolvedObject = argumentsAsAnonymousType != null ? _iocResolver.Resolve(type, argumentsAsAnonymousType) : _iocResolver.Resolve(type); _resolvedObjects.Add(resolvedObject); return(resolvedObject); }
public void Navigate <T>() where T : class { var viewModelType = typeof(T); var frame = (Frame)Window.Current.Content; var viewModel = _resolver.Resolve(viewModelType); frame.Navigate(_pages[viewModelType], viewModel); ((Page)frame.Content).DataContext = viewModel; }
public static PublishCommandJob Create( ICommand command, IResolver resolver) { var commandDefinitionService = resolver.Resolve<ICommandDefinitionService>(); var jsonSerializer = resolver.Resolve<IJsonSerializer>(); return Create(command, commandDefinitionService, jsonSerializer); }
public IConfigurated WithConfiguration(SubscriptionConfiguration configuration) { var serviceBus = _resolver.Resolve <IServiceBus>(); if (_name == null) { return((IConfigurated)serviceBus.Subscribe(_resolver.Resolve <THandler>(), configuration)); } return((IConfigurated)serviceBus.Subscribe(_resolver.ResolveNamed <THandler>(_name))); }
public TDbContext Resolve <TDbContext>(string connectionString) where TDbContext : DbContext { var dbContextType = GetConcreteType <TDbContext>(); return((TDbContext)_iocResolver.Resolve(dbContextType, new { nameOrConnectionString = connectionString })); }
public ResolveResult[] Resolve() { return(new[] { _resolver.Resolve(_instance, "Id"), _resolver.Resolve(_instance, "DecimalProp7"), _resolver.Resolve(_instance, "StringProperty98"), _resolver.Resolve(_instance, "NotAProperty"), }); }
public MailBuilder( IResolver resolver ) { Resolver = resolver; SmtpSettings = resolver.Resolve <IOptions <SmtpSettings> >().Value; HostingEnvironment = resolver.Resolve <IHostingEnvironment>(); From = SmtpSettings.From; FolderPath = $"{HostingEnvironment.WebRootPath}/mailTemplates"; }
/// <summary> /// Selects the initial implementation type using a generic type parameter. /// </summary> /// <returns>A customisation helper by which further implementations may be added to the decorator 'stack'.</returns> /// <param name="autofacParams">An optional collection of <see cref="Parameter"/>.</param> /// <typeparam name="TInitialImpl">The type of the initial concrete implementation.</typeparam> public AutofacDecoratorCustomizer UsingInitialImpl <TInitialImpl>(params Parameter[] autofacParams) where TInitialImpl : class { if (!TypeUtilities.DoesImplTypeDeriveFromServiceType(typeof(TInitialImpl), serviceType)) { throw new ArgumentException($"The implementation type {typeof(TInitialImpl).FullName} must derive from the service type {serviceType.FullName}."); } var initialImpl = resolver.Resolve <TInitialImpl>(autofacParams); return(new AutofacDecoratorCustomizer(resolver, serviceType, initialImpl)); }
/// <summary> /// Selects a decorator type using a generic type parameter. The implementation directly /// before this point in the decorator 'stack' (be it the initial implementation or a /// decorator itself) will be passed to the selected implementation. Thus this implementation /// will 'wrap' the one before it. /// </summary> /// <returns>A customisation helper by which further implementations may be added to the decorator 'stack'.</returns> /// <param name="autofacParams">An optional collection of <see cref="Parameter"/>.</param> /// <typeparam name="TDecorator">The type of the concrete implementation to use as a decorator.</typeparam> public AutofacDecoratorCustomizer ThenWrapWith <TDecorator>(params Parameter[] autofacParams) where TDecorator : class { if (!TypeUtilities.DoesImplTypeDeriveFromServiceType(typeof(TDecorator), serviceType)) { throw new ArgumentException($"The decorator type {typeof(TDecorator).FullName} must derive from the service type {serviceType.FullName}."); } var decoratorImpl = resolver.Resolve <TDecorator>(autofacParams.AddTypedParam(serviceType, Implementation)); return(new AutofacDecoratorCustomizer(resolver, serviceType, decoratorImpl)); }
public Task ExecuteAsync(IResolver resolver, CancellationToken cancellationToken) { var commandDefinitionService = resolver.Resolve <ICommandDefinitionService>(); var jsonSerializer = resolver.Resolve <IJsonSerializer>(); var commandBus = resolver.Resolve <ICommandBus>(); var commandDefinition = commandDefinitionService.GetDefinition(Name, Version); var command = (ICommand)jsonSerializer.Deserialize(Data, commandDefinition.Type); return(command.PublishAsync(commandBus, cancellationToken)); }
public Task ExecuteAsync(IResolver resolver, CancellationToken cancellationToken) { var commandDefinitionService = resolver.Resolve<ICommandDefinitionService>(); var jsonSerializer = resolver.Resolve<IJsonSerializer>(); var commandBus = resolver.Resolve<ICommandBus>(); var commandDefinition = commandDefinitionService.GetDefinition(Name, Version); var command = (ICommand) jsonSerializer.Deserialize(Data, commandDefinition.Type); return command.PublishAsync(commandBus, cancellationToken); }
public THandler ResolveHandler <THandler>() { var handler = _resolver.Resolve <THandler>(); if (handler == null) { throw new HandlerNotFoundException(typeof(THandler)); } return(handler); }
public BaseApiController( IResolver resolver ) { Resolver = resolver ?? throw new ArgumentNullException(nameof(Resolver)); commandProcessor = new Lazy <ICommandProcessor>(resolver.Resolve <ICommandProcessor>()); queryProcessor = new Lazy <IQueryProcessor>(resolver.Resolve <IQueryProcessor>()); notificationProcessor = new Lazy <INotificationProcessor>(resolver.Resolve <INotificationProcessor>()); mailProcessor = new Lazy <IMailProcessor>(resolver.Resolve <IMailProcessor>()); }
public Task ExecuteAsync( IResolver resolver, CancellationToken cancellationToken) { var eventJsonSerializer = resolver.Resolve <IEventJsonSerializer>(); var dispatchToEventSubscribers = resolver.Resolve <IDispatchToEventSubscribers>(); var domainEvent = eventJsonSerializer.Deserialize(Event, Metadata); return(dispatchToEventSubscribers.DispatchToAsynchronousSubscribersAsync( domainEvent, cancellationToken)); }
private static void AssertResolvedValues <TDependency, TImplementation>(IResolver resolver) where TImplementation : class, TDependency { var resolvedValue = resolver.Resolve <TDependency>(); Assert.IsNotNull(resolvedValue); Assert.IsInstanceOfType(resolvedValue, typeof(TImplementation)); resolvedValue = resolver.Resolve(typeof(TDependency)) as TImplementation; Assert.IsNotNull(resolvedValue); Assert.IsInstanceOfType(resolvedValue, typeof(TImplementation)); }
private CommandBase Resolve(Type command) { var instance = _resolver.Resolve(command); if (instance == null && _autoRegister) { _resolver.Register(command); instance = _resolver.Resolve(command); } return((CommandBase)instance); }
public async Task Send <TCommand>(TCommand command) where TCommand : ICommand { Guard.AgainstNull <ArgumentNullException>(command); var commandHandler = resolver.Resolve <ICommandHandlerAsync <TCommand> >(); Guard.AgainstNull <ApplicationException>(commandHandler, $"No handler of type CommandHandlerAsync<TCommand> found for command '" + $"{command.GetType().FullName}'"); await commandHandler.HandleAsync(command); }
public void SetUp() { var codeBase = ReflectionHelper.GetCodeBase(GetType().Assembly); var filesEventStoreDirectory = Path.GetFullPath(Path.Combine(codeBase, "..", "..", "TestData", "FilesEventStore")); _resolver = EventFlowOptions.New .UseFilesEventStore(FilesEventStoreConfiguration.Create(filesEventStoreDirectory)) .AddEvents(EventFlowTestHelpers.Assembly) .AddCommandHandlers(EventFlowTestHelpers.Assembly) .CreateResolver(); _commandBus = _resolver.Resolve <ICommandBus>(); _eventStore = _resolver.Resolve <IEventStore>(); }
public Task PurgeAsync <TReadModel>(CancellationToken cancellationToken) where TReadModel : class, IReadModel, new() { var readModelStores = _resolver.Resolve <IEnumerable <IReadModelStore <TReadModel> > >().ToList(); if (!readModelStores.Any()) { throw new ArgumentException($"Could not find any read stores for read model '{typeof (TReadModel).PrettyPrint()}'"); } var deleteTasks = readModelStores.Select(s => s.DeleteAllAsync(cancellationToken)); return(Task.WhenAll(deleteTasks)); }
public async Task Continues_to_execution_if_handler_resolved() { // Arrange _resolver.Resolve <IHandleCommand <TestCommand> >().Returns(_handler); // Act var dispatcher = CreateDispatcher(); var command = new TestCommand(); await dispatcher.CommandAsync(command); // Assert _resolver.Received(1).Resolve <IHandleCommand <TestCommand> >(); await _executor.Received(1).ExecuteAsync(_handler, command, CancellationToken.None); }
public void SetUp() { var codeBase = ReflectionHelper.GetCodeBase(GetType().Assembly); var filesEventStoreDirectory = Path.GetFullPath(Path.Combine(codeBase, "..", "..", "..", "TestData", "FilesEventStore")); _resolver = EventFlowOptions.New .UseFilesEventStore(FilesEventStoreConfiguration.Create(filesEventStoreDirectory)) .AddEvents(EventFlowTestHelpers.Assembly) .AddCommandHandlers(EventFlowTestHelpers.Assembly) .RegisterServices(sr => sr.Register <IScopedContext, ScopedContext>(Lifetime.Scoped)) .CreateResolver(); _commandBus = _resolver.Resolve <ICommandBus>(); _aggregateStore = _resolver.Resolve <IAggregateStore>(); }
public IRpcClient GetRpcClient(string service) { if (!_resolver.TryResolve(service, out IRpcClientConfig config)) { if (!_resolver.TryResolve(Constants.DefaultsConfigKey, out config)) { throw new ArgumentException("Service Configuration Not Found", nameof(service)); } } var serializer = _resolver.Resolve <ISerializer>(config.Serializer); var factory = _resolver.Resolve <IRpcClientFactory>(config.Protocol); return(factory.GetRpcClient(serializer, _log, config)); }
public async Task ExecuteAsync(IResolver resolver, CancellationToken cancellationToken) { // Consideration: Fetching all cargos that are affected by an updated // schedule could potentially fetch several thousands. Each of these // potential re-routes would then take a considerable amount of time // and will thus be required to be executed in parallel var queryProcessor = resolver.Resolve<IQueryProcessor>(); var jobScheduler = resolver.Resolve<IJobScheduler>(); var cargos = await queryProcessor.ProcessAsync(new GetCargosDependentOnVoyageQuery(VoyageId), cancellationToken).ConfigureAwait(false); var jobs = cargos.Select(c => new VerifyCargoItineraryJob(c.Id)); await Task.WhenAll(jobs.Select(j => jobScheduler.ScheduleNowAsync(j, cancellationToken))).ConfigureAwait(false); }
private void AssertResolveCanResolveIEnumerableType(IResolver resolver, string key = null) { // Test both generic and non - generic ? var result = key == null?resolver.Resolve <IEnumerable <IFoo> >() : resolver.Resolve <IEnumerable <IFoo> >(key); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IEnumerable <IFoo>)); var collection = result.ToArray(); CollectionAssert.AllItemsAreNotNull(collection); CollectionAssert.AllItemsAreUnique(collection); CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(IFoo)); }
public void SetUp() { var codeBase = ReflectionHelper.GetCodeBase(GetType().Assembly); var filesEventStoreDirectory = Path.GetFullPath(Path.Combine(codeBase, "..", "..", "TestData", "FilesEventStore")); _resolver = EventFlowOptions.New .UseFilesEventStore(FilesEventStoreConfiguration.Create(filesEventStoreDirectory)) .AddEvents(EventFlowTestHelpers.Assembly) .AddCommandHandlers(EventFlowTestHelpers.Assembly) .CreateResolver(); _commandBus = _resolver.Resolve<ICommandBus>(); _eventStore = _resolver.Resolve<IEventStore>(); }
public override Func <Scope, object> ToResolver(Scope topScope) { if (_resolver == null) { lock (_locker) { if (_resolver == null) { buildResolver(topScope); } } } return(scope => _resolver.Resolve(scope)); }
public async Task ProcessAsync( IReadOnlyCollection <IDomainEvent> domainEvents, CancellationToken cancellationToken) { var commandBus = _resolver.Resolve <ICommandBus>(); foreach (var domainEvent in domainEvents) { await ProcessAsync( commandBus, domainEvent, cancellationToken) .ConfigureAwait(false); } }
/// <summary> /// Property Level: Gets the cached property handler object that is being mapped on a specific <see cref="PropertyInfo"/> object. /// </summary> /// <typeparam name="TPropertyHandler">The type of the handler.</typeparam> /// <param name="entityType">The type of the data entity.</param> /// <param name="propertyInfo">The instance of <see cref="PropertyInfo"/>.</param> /// <returns>The mapped property handler object of the property.</returns> internal static TPropertyHandler Get <TPropertyHandler>(Type entityType, PropertyInfo propertyInfo) { // Validate ThrowNullReferenceException(propertyInfo, "PropertyInfo"); // Variables var key = GenerateHashCode(entityType, propertyInfo); var value = (object)null; var result = default(TPropertyHandler); // Try get the value if (cache.TryGetValue(key, out value) == false) { value = propertyLevelResolver.Resolve(entityType, propertyInfo); result = Converter.ToType <TPropertyHandler>(value); cache.TryAdd(key, result); } else { // Set the result result = Converter.ToType <TPropertyHandler>(value); } // Return the value return(result); }
public void Initialize(IResolver resolver) { var shell = resolver.Resolve <IShell>(); shell.RegisterSettingView(typeof(LocaleSettingView), SettingCategory.Appearance); shell.RegisterSettingView(typeof(ProxySettingView), SettingCategory.Network); }
public async Task ExecuteAsync(IResolver resolver, CancellationToken cancellationToken) { // Consideration: Fetching all cargos that are affected by an updated // schedule could potentially fetch several thousands. Each of these // potential re-routes would then take a considerable amount of time // and will thus be required to be executed in parallel var queryProcessor = resolver.Resolve <IQueryProcessor>(); var jobScheduler = resolver.Resolve <IJobScheduler>(); var cargos = await queryProcessor.ProcessAsync(new GetCargosDependentOnVoyageQuery(VoyageId), cancellationToken).ConfigureAwait(false); var jobs = cargos.Select(c => new VerifyCargoItineraryJob(c.Id)); await Task.WhenAll(jobs.Select(j => jobScheduler.ScheduleNowAsync(j, cancellationToken))).ConfigureAwait(false); }
private TypeDef ResolverResolve(ITypeDefOrRef typeDefOrRef) { var typeRef = (TypeRef)typeDefOrRef; var typeDef = _resolver.Resolve(typeRef); return(typeDef); }
public TResult Dispatch <TQuery, TResult>(TQuery query) where TQuery : IQuery { if (query == null) { throw new ArgumentNullException(nameof(query)); } var queryHandler = _resolver.Resolve <IQueryHandler <TQuery, TResult> >(); if (queryHandler == null) { throw new Exception($"No handler found for query '{query.GetType().FullName}'"); } return(queryHandler.Retrieve(query)); }
internal void AutoDiscover(IResolver resolver) { var types = _configurator.Assemblies.SelectMany(x => x.GetTypes()).Where(x => x.HasAttribute<MDataAttribute>()).Select(x => x); foreach (var assembly in _configurator.Assemblies) { RegisterAssembly(assembly); } foreach (var type in types) { RegisterDomainInterface(type, GetLogicClass(type)); resolver.Resolve(type); } }
public void Install(DistributedConfiguration distributedConfiguration, string loggerConfiguration) { RegisterLogging(loggerConfiguration); if (distributedConfiguration == null) { // use nomad specific installer for that _windsorContainer.Install( new NomadEventAggregatorInstaller(), new NomadServiceLocatorInstaller(), new ModuleLoaderInstaller() ); } else { // use nomad specific installer for that _windsorContainer.Install( new NomadDistributedDeliverySubsystemsInstaller(distributedConfiguration), new NomadDistributedEventAggregatorInstaller(), new NomadServiceLocatorInstaller(), new ModuleLoaderInstaller() ); // TODO: make registering resolver with container later var dea = (DistributedEventAggregator) _windsorContainer.Resolve<IEventAggregator>(NomadDistributedEventAggregatorInstaller.ON_SITE_NAME); _resolver = new ResolverFactory(distributedConfiguration); dea.RemoteDistributedEventAggregator = _resolver.Resolve(); // run service RegisterServiceHostDEA(distributedConfiguration); } }
private void AssertResolveCanResolveIEnumerableType(IResolver resolver, string key = null) { // Test both generic and non - generic ? var result = key == null ? resolver.Resolve<IEnumerable<IFoo>>() : resolver.Resolve<IEnumerable<IFoo>>(key); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IEnumerable<IFoo>)); var collection = result.ToArray(); CollectionAssert.AllItemsAreNotNull(collection); CollectionAssert.AllItemsAreUnique(collection); CollectionAssert.AllItemsAreInstancesOfType(collection, typeof(IFoo)); }
void RefreshContent(IResolver container, IEnumerable<PostViewModel> posts) { var storage = container.Resolve<MarkdownSharpContentStorage>(); foreach (var post in posts) { storage.Handle(post); } }
public NameValueCollection GetPostData(IResolver resolver) { NameValueCollection postData = new NameValueCollection(); foreach (string key in this.postData.Keys) { postData[key] = resolver.Resolve(this.postData[key].ToString()); } return postData; }
public string GetUrl(IResolver resolver) { string url = resolver.Resolve(this.url); this.result.ExecutedUrl = url; return url; }