Example #1
0
        public async Task Run()
        {
            var containerOptions = new ContainerOptions()
            {
                EnablePropertyInjection = false
            };
            var container = new ServiceContainer(containerOptions);

            container.RegisterFrom <CompositionRoot>();

            RegisterViews(container.GetInstance <INavigator>());

            IFileManager fileManager = container.GetInstance <IFileManager>();

            InitializeData(fileManager);

            App.Navigator = container.GetInstance <INavigator>();

            await ConfigureApplication(container);
        }
Example #2
0
        public void GetConstructor_TypeWithSingleInternalConstructor_ThrowsExpectedException()
        {
            // Arrange
            var behavior = new ContainerOptions().ConstructorResolutionBehavior;

            try
            {
                // Act
                behavior.GetConstructor(typeof(TypeWithSingleInternalConstructor),
                                        typeof(TypeWithSingleInternalConstructor));

                // Assert
                Assert.Fail("Exception expected.");
            }
            catch (ActivationException ex)
            {
                AssertThat.StringContains("For the container to be able to create " +
                                          "DefaultConstructorResolutionBehaviorTests.TypeWithSingleInternalConstructor, it should " +
                                          "contain exactly one public constructor, but it has 0.", ex.Message);
            }
        }
Example #3
0
        private static void ConfigFromObjectInternal(ContainerOptions containerOptions, AppDependenciesObject dependencies)
        {
            // Add Root Assemblies
            var modules = dependencies.AppDependencies.Modules;

            containerOptions.Assemblies = modules == null || modules.Length == 0 ? null : modules;

            if (containerOptions.Assemblies != null)
            {
                // Add dependecies in hirarchy
                AddDependeciesRecursively(containerOptions, dependencies.AppDependencies.Dependencies);

                // Add Shared Dependencies
                if (dependencies.SharedDependencies != null && dependencies.SharedDependencies.Modules != null)
                {
                    containerOptions.AddSharedServices(shared =>
                    {
                        var sharedModules = dependencies.SharedDependencies.Modules;
                        shared.Assemblies = sharedModules == null || sharedModules.Length == 0 ? null : sharedModules;
                    });
                }
            }
        }
Example #4
0
        public static ServiceContainer ConfigureService()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-BR");

            var containerOptions = new ContainerOptions {
                EnablePropertyInjection = false
            };
            var container = new ServiceContainer(containerOptions);

            container.RegisterInstance(
                new WorldMarketsServiceScrap(new WorldMarketServicesApi(), new ScrapParser())
                );

            container.RegisterInstance(
                new WorldMarketsService(container.GetInstance <WorldMarketsServiceScrap>())
                );

            container.RegisterInstance(
                new WorldMarketsController(container.GetInstance <WorldMarketsService>())
                );

            container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();
            return(container);
        }
Example #5
0
        public override bool Commit(ContainerOptions options)
        {
            //暗号アルゴリズム順序はoptionsを直接いじっているのでここでは何もしなくてよい
            try {
                PublicKeyAlgorithm[] pa = new PublicKeyAlgorithm[2];
                if (_hostKeyBox.SelectedIndex == 0)
                {
                    pa[0] = PublicKeyAlgorithm.DSA;
                    pa[1] = PublicKeyAlgorithm.RSA;
                }
                else
                {
                    pa[0] = PublicKeyAlgorithm.RSA;
                    pa[1] = PublicKeyAlgorithm.DSA;
                }
                options.HostKeyAlgorithmOrder = LocalSSHUtil.FormatPublicKeyAlgorithmList(pa);

                try {
                    options.SSHWindowSize = Int32.Parse(_windowSizeBox.Text);
                }
                catch (FormatException) {
                    GUtil.Warning(this, GApp.Strings.GetString("Message.OptionDialog.InvalidWindowSize"));
                    return(false);
                }

                options.RetainsPassphrase    = _retainsPassphrase.Checked;
                options.SSHCheckMAC          = _sshCheckMAC.Checked;
                options.CipherAlgorithmOrder = _cipherAlgorithmOrder;

                return(true);
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                return(false);
            }
        }
        public override bool Commit(ContainerOptions options)
        {
            string itemname = "";

            try {
                options.UseSocks = _useSocks.Checked;
                if (options.UseSocks && _socksServerBox.Text.Length == 0)
                {
                    throw new Exception(GApp.Strings.GetString("Message.OptionDialog.EmptySocksServer"));
                }
                options.SocksServer   = _socksServerBox.Text;
                itemname              = GApp.Strings.GetString("Caption.OptionDialog.SOCKSPortNumber");
                options.SocksPort     = Int32.Parse(_socksPortBox.Text);
                options.SocksAccount  = _socksAccountBox.Text;
                options.SocksPassword = _socksPasswordBox.Text;
                itemname              = GApp.Strings.GetString("Caption.OptionDialog.NetworkAddress");
                foreach (string c in _socksNANetworksBox.Text.Split(';'))
                {
                    if (!NetUtil.IsNetworkAddress(c))
                    {
                        throw new FormatException();
                    }
                }
                options.SocksNANetworks = _socksNANetworksBox.Text;

                return(true);
            }
            catch (FormatException) {
                GUtil.Warning(this, String.Format(GApp.Strings.GetString("Message.OptionDialog.InvalidItem"), itemname));
                return(false);
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                return(false);
            }
        }
 internal ImplicitPropertyInjectionBehavior(IPropertySelectionBehavior core,
     ContainerOptions options)
 {
     this.core = core;
     this.options = options;
 }
 internal virtual IServiceContainer CreateContainer(ContainerOptions options)
 {
     return ContainerFactory.CreateContainer(options);
 }        
 internal static IServiceContainer CreateContainer(ContainerOptions options)
 {
     return new ServiceContainer(options);
 }
 public static void EnableSkippingOptionalConstructorArguments(ContainerOptions options)
 {
     options.DependencyInjectionBehavior =
         new OptionalArgumentsInjectionBehavior(options.Container, options.DependencyInjectionBehavior);
 }
 public void RegisterPropertyDependency_AfterFirstGetInstance_ShouldLogWarning()
 {
     string message = null;
     var options = new ContainerOptions() { LogFactory = type => (entry => message = entry.Message) };
     var container = CreateContainer(options);
     container.Register<IFoo, Foo>();
     container.GetInstance<IFoo>();
     container.RegisterPropertyDependency<IBar>((factory, info) => new Bar());
     Assert.StartsWith("Attempt to register", message);
 }