Exemplo n.º 1
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(object activationScope, IDIContainer container)
        {
            // Hack to allow IDataProvider to resolve on time
            // (we allow other widgets to be resolved and register the dependency required, while this one is in waiting state)
            return(ResolutionStepResult.WAITING_FOR_SERVICE
                   .Repeat(1) // skip specified amount of steps
                   .Concat(Helpers.CoroutineEnumerable(instantiate))
                   .GetEnumerator());

            void instantiate()
            {
                var dr = new DeviceDataRequestVM(
                    container.ResolveSingle <IRUSDevice>(),
                    container.ResolveSingle <BusyObject>(),
#warning will not return all providers if at the time of resolving not all of them were registered
                    container.TryResolveAll <IDataProvider>()?.ToArray() ?? new IDataProvider[0]);
                var widget = new DataRequest()
                {
                    Model = new DataRequestVM(container.ResolveSingle <IRUSDevice>(),
                                              dr,
                                              new DeviceDataAutorequestVM(dr.GetDataRequest, container.ResolveSingle <BusyObject>())),
                    FunctionId = new WidgetIdentity("Опрос",
                                                    container.ResolveSingle <string>(),
                                                    activationScope)
                };

                container.Register <IWidget>(widget);
                container.Register <IDeviceHandler>(widget.Model);
                container.Register <IDataStorageVM>(widget.Model.RequestVM.DeviceDataVM, activationScope);
                container.Register <IPointsStorageProvider>(widget.Model.RequestVM.DeviceDataVM, activationScope);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            IDIContainer di = CreateDI();

            di.Register <IWCFConfigManager>(() => new WCFConfigManager());

            IRemoteOperationHandler roh = new RemoteOperationHandler(di);
            RemoteSideCommunicator  roc = new RemoteSideCommunicator(roh);

            di.Register <IRemoteSideCommunicationContract>(() => roc);
            di.Register <IRemoteSideCommunicationHandler>(() => roc);

            WCFServiceClientFactory factory = new WCFServiceClientFactory(di);
            var rs = factory.CreateInstance();

            System.Console.WriteLine("Client started!");
            System.Console.WriteLine("Press Enter to call server side Add method.");
            System.Console.ReadLine();

            RemoteOperationDescriptor rod = new RemoteOperationDescriptor(typeof(ICalc).AssemblyQualifiedName, "Add", 1, 2);
            int sum = roc.ExecuteOnRemoteSide <int>(rs.ID, rod);

            System.Console.WriteLine("Add(1,2) = {0}", sum);
            System.Console.WriteLine("Press Enter to stop service client!");
            System.Console.ReadLine();
        }
Exemplo n.º 3
0
        public void Register(IDIContainer container)
        {
            container.Register <ILocalization, Localization>();
            container.Register(typeof(IRelayCommand <>), typeof(RelayCommand <>));

            Setup(container);
        }
 private void RegisterJobs(IDIContainer container)
 {
     container.Register <ILoggingJob, LoggingJob>();
     container.Register <LoggingJob, LoggingJob>();
     container.Register <IUpdateServerPropertiesJob, UpdateServerPropertiesJob>();
     container.Register <UpdateServerPropertiesJob, UpdateServerPropertiesJob>();
 }
Exemplo n.º 5
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(bool isStaticData, object activationScope, IDIContainer container)
        {
            return(Helpers.Coroutine(instantiate));

            void instantiate()
            {
                var widget = new DataViewSettings()
                {
                    Model = new DataViewSetingVM(
                        container.ResolveSingle <IDataStorageVM>(activationScope),
                        container.ResolveSingle <IGraphicViewSetingVM>(activationScope),
                        #warning same issue here
                        container.ResolveAll <ICurvesExporterVM>(activationScope).ToArray()),
                    FunctionId = new WidgetIdentity("Отображение",
                                                    container.ResolveSingle <string>(),
                                                    activationScope)
                };

                if (isStaticData)
                {
                    widget.Model.ViewSetingVM.IsAutoscrollEnabled   = false;
                    widget.Model.ViewSetingVM.IsAutoscrollSupported = false; // because data from flash are static
                    widget.Model.ViewSetingVM.IsClearSupported      = false;
                }

                container.Register <IWidget>(widget);
            }
        }
Exemplo n.º 6
0
        static IEnumerator <ResolutionStepResult> injectExporters(IDIContainer container, object scope)
        {
            while (true)
            {
                var exporters = CommonUtils.TryOrNull <ICurvesExporterVM[], ServiceIsNotYetAwailableException>(() => instantiate().ToArray());
                if (exporters == null)
                {
                    yield return(ResolutionStepResult.WAITING_FOR_SERVICE);
                }
                else
                {
                    foreach (var exporter in exporters)
                    {
                        container.Register <ICurvesExporterVM>(exporter, scope);
                    }

                    yield return(ResolutionStepResult.RESOLVED);
                }
            }

            IEnumerable <ICurvesExporterVM> instantiate()
            {
                var storage = container.ResolveSingle <IPointsStorageProvider>(scope);

                yield return(new LasCurvesExporterVM(storage));
            }
        }
Exemplo n.º 7
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(Command command, object activationScope, IDIContainer serviceProvider)
        {
            return(ResolutionStepResult.WAITING_FOR_SERVICE.Repeat(3).Concat(Helpers.CoroutineEnumerable(instantiate)).GetEnumerator());

            void instantiate()
            {
                var handler = serviceProvider.TryResolveSingle <ICommandHandlerWidget>(command);

                activationScope = handler?.FunctionId?.ActivationScope ?? activationScope;
                var widgetName = handler?.FunctionId?.Name ?? command.GetInfo().CommandName;
                var widget     = new DeviceCommand()
                {
                    Model = new DeviceCommandVM(
                        serviceProvider.ResolveSingle <IRUSDevice>(),
                        command,
                        handler,
                        serviceProvider.ResolveSingle <BusyObject>()),
                    FunctionId = new WidgetIdentity(widgetName,
                                                    serviceProvider.ResolveSingle <string>(),
                                                    activationScope)
                };

                serviceProvider.Register <IWidget>(widget);
            }
        }
        public void Register(IDIContainer container)
        {
            container.Register <ILogFactory, InjectedLogFactory>();
            container.Register <ILog, BroadcastLogger>();
            container.Register <ILog, SerilogLogger>(typeof(SerilogLogger).FullName);

            container.Register <IEventTimingFactory, EventTimingRecorderFactory>();
            container.Register <IInlineEventTimer, InlineEventTimer>();
            container.Register <IInstrumentationEntity, InstrumentationEntity>();
            container.Register <ICaptureAndAggregate, TimerCaptureAndAggregate>();
            container.Register <IMetricAggregator, MetricAggregator>();
        }
Exemplo n.º 9
0
        static IEnumerator <ResolutionStepResult> injectCalibrationWidgets(IDIContainer container, ICalibrator calibrator)
        {
            //Skip(1) because the first item is calibration widget itself
            foreach (var calibrationDataWidget in calibrator.Widgets.Skip(1))
            {
                container.Register <IWidget>(calibrationDataWidget);
            }

            yield return(ResolutionStepResult.RESOLVED);
        }
Exemplo n.º 10
0
 public void Register(IDIContainer container)
 {
     if (!container.IsRegistered <IConfiguration>())
     {
         container.Register <IConfiguration, Configuration>();
         var config = container.Resolve <IConfiguration>();
         config.Build();
         container.RegisterInstance(config, typeof(IConfiguration));
     }
 }
Exemplo n.º 11
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(string name, object activationScope, IDIContainer container)
        {
            return(Helpers.Coroutine(instantiate));

            void instantiate()
            {
                var widget = new DataView()
                {
                    Model = new DataViewVM(
                        container.ResolveSingle <IDataStorageVM>(activationScope)),
                    FunctionId = new WidgetIdentity(name,
                                                    container.ResolveSingle <string>(),
                                                    activationScope)
                };

                container.Register <IGraphicViewSetingVM>(widget.Model.GraphicVM.Settings, activationScope);
                container.Register <IWidget>(widget);
            }
        }
Exemplo n.º 12
0
        public void Register(IDIContainer container)
        {
            if (!container.IsRegistered <ISerialize>())
            {
                new CoreServicesRegistrationContainer().Register(container);
            }
            if (!container.IsRegistered <ILogFactory>())
            {
                new LoggingRegistrationContainer().Register(container);
            }
            if (!container.IsRegistered <ICacheFactory>())
            {
                new CacheRegistrationContainer().Register(container);
            }

            container.Register <IResourceCompiler, ResourceCompiler>();
            container.Register <INeonTetraResources, NeonTetraResourceCache>();
            container.Register <ISpecificCultureTranslations, SpecificCultureTranslations>("DEFAULT");
        }
Exemplo n.º 13
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(object activationScope, IDIContainer container)
        {
            return(Helpers.Coroutine(instantiate));

            void instantiate()
            {
                var widget = new RUSTelemetryStreamSender()
                {
                    Model = new RUSTelemetryStreamSenderVM(
                        container.ResolveSingle <IRUSDevice>(),
                        container.ResolveSingle <BusyObject>()),
                    FunctionId = new WidgetIdentity("Отправка кривой давления",
                                                    container.ResolveSingle <string>(),
                                                    activationScope)
                };

                container.Register <IDataProvider>(widget.Model);
                container.Register <IWidget>(widget);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Inspired by coroutines from Unity3D
        /// </summary>
        /// <param name="calibrator"></param>
        /// <param name="container"></param>
        /// <returns></returns>
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(ICalibrator calibrator, object activationScope, IDIContainer container)
        {
            return(Helpers.Coroutine(instantiate));

            void instantiate()
            {
                var widget = new DeviceCalibration()
                {
                    Model = new DeviceCalibrationVM(calibrator,
                                                    container.ResolveSingle <IDeviceInitializationVM>(),
                                                    container.ResolveSingle <BusyObject>()),
                    FunctionId = new WidgetIdentity(calibrator.Model.CalibrationName,
                                                    container.ResolveSingle <string>(),
                                                    activationScope)
                };

                widget.View.Visibility = Visibility.Collapsed;

                container.Register <IWidget>(widget);
                container.Register <IDataProvider>(calibrator.Model.DataProvider);
            }
        }
 /// <summary>
 /// init di container
 /// </summary>
 /// <param name="defaultServices">default services</param>
 /// <param name="container">DI container</param>
 /// <param name="serviceRegisterAction">service register action</param>
 public static void Init(IServiceCollection defaultServices = null, IDIContainer container = null, Action <IDIContainer> serviceRegisterAction = null)
 {
     defaultServices = defaultServices ?? new ServiceCollection();
     container       = container ?? new ServiceProviderContainer();
     SetDefaultServiceCollection(defaultServices);
     if (defaultServices != null && !(container is ServiceProviderContainer))
     {
         container.Register(defaultServices.ToArray());
     }
     serviceRegisterAction?.Invoke(container);
     SetDefaultServiceCollection(defaultServices);
     Container = container;
 }
        private void RegisterActorMessageTypes(IDIContainer container)
        {
            container.Register <ICommandToEventAdapter, CommandToEventAdapter>();

            //messages/commands/events
            container.Register <IRespondActorStateEvent, RespondActorStateEvent>();
            container.Register <IUpdateUserActorStateCommand, UpdateUserActorStateCommand>();

            container.Register <IRequestTrackUserCommand, RequestTrackUserCommand>();
            container.Register <IUserTrackingEvent, UserTrackingEvent>();
            container.Register <IUserUpdatedEvent, UserUpdatedEvent>();

            container.Register <IRequestUserLoginCommand, RequestUserLoginCommand>();
            container.Register <IRespondUserLoginEvent, RespondUserLoginEvent>();
        }
Exemplo n.º 17
0
        public static void Main(string[] args)
        {
            IDIContainer di = CreateDI();

            di.Register <IWCFConfigManager>(() => new WCFConfigManager());
            di.Register <ICalc>(() => new CalcImpl());

            IRemoteOperationHandler roh = new RemoteOperationHandler(di);
            RemoteSideCommunicator  roc = new RemoteSideCommunicator(roh);

            di.Register <IRemoteSideCommunicationContract>(() => roc);
            di.Register <IRemoteSideCommunicationHandler>(() => roc);

            WCFServiceHostFactory factory = new WCFServiceHostFactory(di);
            var rs = factory.CreateInstance();

            rs.Open();

            System.Console.WriteLine("Server started!");
            System.Console.WriteLine("Waiting for client operations!");
            System.Console.WriteLine("Press Enter to stop service host!");
            System.Console.ReadLine();
        }
Exemplo n.º 18
0
        public void Register(IDIContainer container)
        {
            container.Register <IAttachment, Attachment>();
            container.Register <IBotClient, BotClient>();
            container.Register <IChannelAccount, ChannelAccount>();
            container.Register <ILocation, Location>();
            container.Register <IMention, Mention>();
            container.Register <IMessage, Message>();
            container.Register <IMojioConversationData, MojioConversationData>();
            container.Register <IEntity, Entity>();
            container.Register <IIntent, Intent>();

            var botAccount = container.Resolve <IChannelAccount>();

            botAccount.Id      = "kitt-mojio-1";
            botAccount.Address = "1080 Howe Street, Vancouver, BC Canada";
            botAccount.IsBot   = true;
            botAccount.Name    = "Kitt";
            container.RegisterInstance(botAccount, "bot");
        }
Exemplo n.º 19
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(object activationScope, IDIContainer serviceProvider)
        {
            return(Helpers.Coroutine(instantiate));

            void instantiate()
            {
                var widget = new DeviceInitialization()
                {
                    Model = new DeviceInitializationVM(
                        serviceProvider.ResolveSingle <IRUSDevice>(),
                        serviceProvider.ResolveSingle <BusyObject>(),
                        new WriteFilesByDefaultVM(
                            serviceProvider.ResolveSingle <IRUSDevice>(),
                            serviceProvider.ResolveSingle <BusyObject>())),
                    FunctionId = new WidgetIdentity("Инициализация устройства",
                                                    serviceProvider.ResolveSingle <string>(),
                                                    activationScope)
                };

                widget.Visibility = Visibility.Collapsed;
                serviceProvider.Register <IDeviceInitializationVM>(widget.Model);
                serviceProvider.Register <IWidget>(widget);
            }
        }
        public void Register(IDIContainer container)
        {
            container.Register(typeof(ICache <,>), typeof(NonStaticImmutableInMemoryCache <,>));
            container.Register(typeof(ICache <,>), typeof(NonStaticImmutableInMemoryCache <,>), "DEFAULT");
            container.Register(typeof(ICache <,>), typeof(NonStaticImmutableInMemoryCache <,>), "INMEMORY_REQUESTS");
            container.Register <ICacheFactory, SimpleCacheFactory>();

            container.Register <IKnownCacheSetup, KnownCacheSetup>();
            container.Register <IKnownCacheConfiguration, KnownCacheConfiguration>();
        }
Exemplo n.º 21
0
 /// <summary>
 /// Init dependency injection container
 /// </summary>
 /// <param name="defaultServices">Default services</param>
 /// <param name="container">Dependency injection container</param>
 /// <param name="configureServiceAction">Configure service action</param>
 /// <param name="registerDefaultProjectService">Whether register default project service</param>
 public static void Init(IServiceCollection defaultServices = null, IDIContainer container = null, Action <IDIContainer> configureServiceAction = null, bool registerDefaultProjectService = true)
 {
     defaultServices ??= new ServiceCollection();
     container ??= new ServiceProviderContainer();
     SetDefaultServiceCollection(defaultServices);
     if (defaultServices != null && !(container is ServiceProviderContainer))
     {
         container.Register(defaultServices.ToArray());
     }
     RegisterComponentConfiguration();
     if (registerDefaultProjectService)
     {
         RegisterDefaultProjectService();
     }
     configureServiceAction?.Invoke(container);
     SetDefaultServiceCollection(defaultServices);
     Container = container;
 }
        public void Register(IDIContainer container)
        {
            new CoreServicesRegistrationContainer().Register(container);
            new ConfigurationRegistrationContainer().Register(container);
            new LoggingRegistrationContainer().Register(container);
            new CacheRegistrationContainer().Register(container);
            new ResourceCompilerRegistrationContainer().Register(container);
            new AkkaRegistrationContainer().Register(container);
            new MqttBrokerRegistrationContainer().Register(container);
            new SunriseSunsetRegistrationContainer().Register(container);

            container.Register <IPostRegistrationStep, DefaultDeploymentRegistrationContainer>("DefaultDeploymentRegistrationContainer");
            container.Register <IPostRegistrationStep, LoggingRegistrationContainer>("LoggingRegistrationContainer");
            container.Register <IPostRegistrationStep, ConfigurationRegistrationContainer>("ConfigurationRegistrationContainer");
            container.Register <IPostRegistrationStep, CacheRegistrationContainer>("CacheRegistrationContainer");
            container.Register <IPostRegistrationStep, ResourceCompilerRegistrationContainer>("ResourceCompilerRegistrationContainer");
            container.Register <IPostRegistrationStep, AkkaRegistrationContainer>("AkkaRegistrationContainer");
            container.Register <IPostRegistrationStep, MqttBrokerRegistrationContainer>("MqttBrokerRegistrationContainer");
            container.Register <IPostRegistrationStep, SunriseSunsetRegistrationContainer>("SunriseSunsetRegistrationContainer");
        }
Exemplo n.º 23
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(object activationScope, IDIContainer serviceProvider)
        {
            return(Helpers.Coroutine(instantiate));

            void instantiate()
            {
                var widget = new RUSModuleSetDirection()
                {
                    Model = new RUSModuleSetDirectionVM(
                        serviceProvider.ResolveSingle <IRUSDevice>(),
                        serviceProvider.ResolveSingle <BusyObject>()),
                    FunctionId = new WidgetIdentity("Настройки бурения",
                                                    serviceProvider.ResolveSingle <string>(),
                                                    activationScope)
                };

                serviceProvider.Register <IWidget>(widget);
            }
        }
Exemplo n.º 24
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(object activationScope, IDIContainer container)
        {
            return(Helpers.Coroutine(instantiate));

            void instantiate()
            {
                var widget = new DeviceStatus()
                {
                    Model = new DeviceStatusVM(
                        container.ResolveSingle <IRUSDevice>(),
                        container.ResolveSingle <BusyObject>()),
                    FunctionId = new WidgetIdentity("Статус",
                                                    container.ResolveSingle <string>(),
                                                    activationScope)
                };

                container.Register <IWidget>(widget);
            }
        }
Exemplo n.º 25
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(object activationScope, IDIContainer serviceProvider)
        {
            return(Helpers.Coroutine(instantiate));

            void instantiate()
            {
                var widget = new FlashUploadCommand()
                {
                    Model = new FlashUploadCommandVM(
                        serviceProvider.ResolveSingle <IRUSDevice>(),
                        serviceProvider.ResolveSingle <IFlashDumpDataParserFactory>(),
                        serviceProvider.ResolveSingle <IFlashDumpSaver>(),
                        serviceProvider.ResolveSingle <IFlashDumpLoader>(),
                        serviceProvider.ResolveSingle <BusyObject>()),
                    FunctionId = new WidgetIdentity("Чтение дампа Flash",
                                                    serviceProvider.ResolveSingle <string>(),
                                                    activationScope)
                };

                //serviceProvider.Register<IWidget>(widget);
                serviceProvider.Register <ICommandHandlerWidget>(widget, Command.DOWNLOAD_FLASH);
            }
        }
Exemplo n.º 26
0
        public static IEnumerator <ResolutionStepResult> InstantiationCoroutine(object activationScope, IDIContainer container)
        {
            return(Helpers.Coroutine(instantiate));

            void instantiate()
            {
                var widget = new FlashDumpLoad()
                {
                    Model = new FlashDumpLoadVM(
                        container.ResolveSingle <IRUSDevice>().Id,
                        container.ResolveSingle <BusyObject>()),
                    FunctionId = new WidgetIdentity("Загрузка дампа Flash",
                                                    container.ResolveSingle <string>(),
                                                    activationScope)
                };

                container.Register <IWidget>(widget);
                container.Register <IFlashDumpLoader>(widget.Model);
                container.Register <IFlashDumpDataParserFactory>(FlashDumpDataParserFactory.Instance);
                container.Register <IFlashDumpSaver>(FlashDumpSaverFactory.Instance);
                container.Register <IDataStorageVM>(widget.Model.DataStorageVM, activationScope);
                container.Register <IPointsStorageProvider>(widget.Model, activationScope);
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// 自定义服务注入
 /// </summary>
 /// <param name="container"></param>
 static void RegisterServices(IDIContainer container)
 {
     WebDependencyInjectionManager.ConfigureDefaultWebService();
     container.Register(typeof(VerificationCodeProvider), typeof(SkiaSharpVerificationCode));
 }
Exemplo n.º 28
0
        public void Register(IDIContainer container)
        {
            container.RegisterInstance(container, typeof(IDIContainer));
            container.RegisterInstance(container, typeof(IRegister));
            container.RegisterInstance(container, typeof(IResolve));

            container.Register <ISerializerFactory, SerializerFactory>();

            container.Register <ISerialize, JsonSerializer>();
            container.Register <ISerializer, JsonSerializer>();
            container.Register <IDeserialize, JsonSerializer>();

            JsonConvert.DefaultSettings = () =>
            {
                var settings = new JsonSerializerSettings();
                settings.ContractResolver = new ContractResolver(container);
                // do something with settings
                return(settings);
            };

            container.Register <ISerialize, JsonSerializer>(KnownSerializerFormats.JSON.ToString());
            container.Register <ISerializer, JsonSerializer>(KnownSerializerFormats.JSON.ToString());
            container.Register <IDeserialize, JsonSerializer>(KnownSerializerFormats.JSON.ToString());

            container.Register <ISerialize, JsonSerializer>(KnownSerializerIntents.Logging.ToString());
            container.Register <ISerializer, JsonSerializer>(KnownSerializerIntents.Logging.ToString());
            container.Register <IDeserialize, JsonSerializer>(KnownSerializerIntents.Logging.ToString());

            container.Register <IEncryptionFactory, BasicEncryptionFactory>();
            container.Register <IEncryption, BasicEncryption>();
            container.Register <IEncrypter, BasicEncryption>();
            container.RegisterInstance(EncryptionAlgorithm.Rijndael, typeof(EncryptionAlgorithm));
            container.Register <IDecrypter, BasicEncryption>();
            container.Register <IEncryptionKeyReadProvider, ConfigurationBasedEncryptionKeyProvider>();
            container.Register <IEncryptionKey, EncryptionKey>();
            container.Register <IValidateEncryptionKeys, ValidateEncryptionKeys>();

            container.RegisterSingleton <IVersionProvider, AssemblyInfoVersionProvider>();
            container.Register <IContractResolver, ContractResolver>();

            container.Register <ICompressionFactory, CompressionFactory>();
            container.Register <ICompression, Compression>();

            container.Register <ICharacterEncodingConverter, CharacterEncodingConverter>();

            container.Register(typeof(IProgress <>), typeof(Progress <>));

            container.Register(typeof(ITimedBufferBatch <>), typeof(TimedBufferBatch <>));
            container.Register(typeof(ITimedBufferBatchWithErrorRetries <>), typeof(TimedBufferBatchWithErrorRetries <>));

            container.Register <IFeatureFlagProvider, ConfigurationBasedFeatureFlagProvider>();

            container.Register <IDomainDataLoader, DomainDataLoader>();
            container.Register <IUser, User>();

            RegisterActorMessageTypes(container);
        }
Exemplo n.º 29
0
        public virtual void Register <T>(T service, object scope = null) where T : class
        {
            throwIfDisposed();

            _base.Register(service, scope);
        }
Exemplo n.º 30
0
 public void Register(IDIContainer container)
 {
     container.Register <IScheduler, BasicHangfireScheduler>();
     container.Register <ICronExpressions, HangFireCronProvider>();
 }