Inheritance: MonoBehaviour
Example #1
0
 public void TestCommandserviceC()
 {
     var container = new DependencyInjector(new ServiceConfiguration(), new ServiceConfigurationC());
     var service = container.GetObject<ISomeDomainCmdService>("C");
     Assert.IsNotNull(service);
     Assert.IsInstanceOf<SomeDomainCmdServiceC>(service);
 }
Example #2
0
 public void TestAmbiguesObjectResolvement()
 {
     var container = new DependencyInjector(new ServiceConfiguration(), new ServiceConfigurationC());
     var composit = container.GetObject<Composit>();
     Assert.IsNotNull(composit);
     Assert.IsInstanceOf<SomeDomainCmdServiceD>(composit.Service);
 }
Example #3
0
        public void TestContainsPrototypeWithObjectArg()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig(), new ServiceConfigurationC()).Reconfigure();

            bool b = container.ContainsObject(typeof(Prototype));
            Assert.IsTrue(b);
        }
Example #4
0
        public void TestConfigurationExpansion()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            Assert.IsNotNull(container);

            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));

            container.ExpandConfiguration(new ComplexConfig());
            Assert.IsTrue(container.ContainsObject<IAggregate>());
        }
Example #5
0
        private static void Prepare()
        {
            Injector = new DependencyInjector(new string[]
                                              {
                                                  IoHelpers.GetStartupPath(),
                                                  IoHelpers.GetActionPath()
                                              });

            var templatePath = Path.Combine(IoHelpers.GetStartupPath(), "Templates");
            if (!Directory.Exists(templatePath))
                Directory.CreateDirectory(templatePath);
        }
Example #6
0
        public void TestDisposeAndReConfiguration()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            Assert.IsNotNull(container);

            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));

            container.ExpandConfiguration(new ComplexConfig());
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            container.Reconfigure();
            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            IAggregate aggregate = container.GetObject<IAggregate>();
            Assert.IsNotNull(aggregate);

            var b = container.GetObject("SomeDomainCmdServiceB");
            Assert.IsNotNull(b);

            container.Dispose();

            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject("SomeDomainCmdServiceB"));
            container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            Assert.IsNotNull(container);

            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));

            container.ExpandConfiguration(new ComplexConfig());
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            container.Reconfigure();
            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            aggregate = container.GetObject<IAggregate>();
            Assert.IsNotNull(aggregate);

            b = container.GetObject("SomeDomainCmdServiceB");
            Assert.IsNotNull(b);
        }
Example #7
0
 public static void Init()
 {
     DependencyInjector.Register <IStorageBL, StorageBL>();
     DependencyInjector.Register <IMessageQueueHandler <Game>, MessageQueueHandler <Game> >();
     DependencyInjector.Register <IStorageRepo, DbRepo>();
 }
Example #8
0
        public void TestGetObjectsInheritingFromPrototypeSuperClassFromContainer()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig());
            container.Reconfigure();

            List<Prototype> prototypes = container.GetAllObjectsInheriting<Prototype>();
            Assert.AreEqual(1, prototypes.Count);
        }
Example #9
0
        public IHashTestHost CreateInstance(TestContext context)
        {
            var provider = DependencyInjector.Get <ICryptoProvider> ();

            return(provider.GetHashTestHost(ProviderType));
        }
 public override void Initialize()
 {
     base.Initialize();
     DependencyInjector.RegisterDependency <IBuiltinTestServer> (() => new BuiltinTestServer());
 }
 private void fun(DependencyInjector pdi, Constructed ca, Constructed cb, Constructed cc)
 {
 }
Example #12
0
 public DiInstanceProvider(DependencyInjector container, Type serviceType)
 {
     this.serviceType = serviceType;
     this.container = container;
 }
 public static void ConfigureDependencyInjector(this IServiceCollection services)
 {
     DependencyInjector.Configure(services);
 }
Example #14
0
 public void TestSimpleOrderingOfObjectsInMetaDataMap()
 {
     var container = new DependencyInjector(new ServiceConfiguration());
     Assert.IsNotNull(container);
     Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
     Assert.IsTrue(container.ContainsObject<ICommandManager>());
 }
Example #15
0
 public DiServiceBehavior(DependencyInjector container)
 {
     this.container = container;
 }
Example #16
0
 public DiServiceHostFactory(DependencyInjector container)
     : base(container)
 {
 }
Example #17
0
        public void TestOrderingOfAggregatedObjectsInMetaDataMap()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig(), new ComplexConfig());
            Assert.IsNotNull(container);

            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));
            Assert.IsTrue(container.ContainsObject<IAggregate>());
        }
Example #18
0
        public void TestGetPrototypeFromContainerObjArgsWithId()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig(), new ServiceConfigurationC()).Reconfigure();

            Prototype prototype = (Prototype)container.GetObject(typeof(Prototype).FullName);
            Assert.IsNotNull(prototype);
        }
Example #19
0
        public void TestGetPrototypeFromContainerGenericArgs()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig(), new ServiceConfigurationC()).Reconfigure();

            Prototype prototype = container.GetObject<Prototype>();
            Assert.IsNotNull(prototype);
        }
Example #20
0
        public void TestGetObjectsInheritingFromSuperClassFromContainer()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig());
            container.Reconfigure();
            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            List<ISomeDomainCmdService> someDomainCmdServices = container.GetAllObjectsInheriting<ISomeDomainCmdService>();
            Assert.AreEqual(2, someDomainCmdServices.Count);

            List<SomeDomainCmdServiceC> someDomainCmdServicesC = container.GetAllObjectsInheriting<SomeDomainCmdServiceC>();
            Assert.AreEqual(0, someDomainCmdServicesC.Count);
        }
Example #21
0
        static void Main(string[] args)
        {
            DependencyInjector.Setup(new BaseDirectoryAssemblyContainer())
            .RegisterAssemblies <AssemblyInfoBase>();

            if (args != null && args.Length > 0 && args[0].StartsWith("fsmt", StringComparison.OrdinalIgnoreCase))
            {
                new Monitor.FileSystemMonitorTest().Run();
                new Monitor.FileSystemMonitorAnotherTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("bdact", StringComparison.OrdinalIgnoreCase))
            {
                new DependencyInjection.BaseDirectoryAssemblyContainerTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("bdcct", StringComparison.OrdinalIgnoreCase))
            {
                new DependencyInjection.BaseDirectoryConfigurableContainerTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("cache", StringComparison.OrdinalIgnoreCase))
            {
                new Caching.CacheContainerBaseTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("sfct", StringComparison.OrdinalIgnoreCase))
            {
                new Configuring.StaticFileConfigurerTest().Run1();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("dpgt", StringComparison.OrdinalIgnoreCase))
            {
                new DynamicProxy.DynamicProxyGeneratorTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("jft", StringComparison.OrdinalIgnoreCase))
            {
                new Formatter.JsonFormatterTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("jfpt", StringComparison.OrdinalIgnoreCase))
            {
                new Formatter.JsonFormatterPerformanceTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("flt", StringComparison.OrdinalIgnoreCase))
            {
                new Logging.FileLoggerTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("tcplot", StringComparison.OrdinalIgnoreCase))
            {
                new Network.Socket.TcpListenerObjectTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("dcct", StringComparison.OrdinalIgnoreCase))
            {
                new EntityFramework.DatabaseCommandConfigurationTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("rt", StringComparison.OrdinalIgnoreCase))
            {
                new Data.ReplicatorTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("ct", StringComparison.OrdinalIgnoreCase))
            {
                new Data.ComparerTest().Run();
                Console.ReadKey();
            }
            else if (args != null && args.Length > 0 && args[0].StartsWith("jdt", StringComparison.OrdinalIgnoreCase))
            {
                new Jobs.JobDispatcherTest().Run();
                Console.ReadKey();
            }
        }
Example #22
0
 public DiServiceHost(DependencyInjector container, Type serviceType, params Uri[] baseAddresses)
     : base(serviceType, baseAddresses)
 {
     this.container = container;
 }
        public Stream CreateClientStream(TestContext ctx, Connection connection, Socket socket)
        {
            if ((EffectiveFlags & InstrumentationFlags.NeedClientInstrumentation) == 0)
            {
                throw ctx.AssertFail("CreateClientStream()");
            }

            var name            = string.Format("Client:{0}", EffectiveType);
            var ownsSocket      = !HasFlag(InstrumentationFlags.ReuseClientSocket);
            var instrumentation = new StreamInstrumentation(ctx, name, socket, ownsSocket);

            var setup = DependencyInjector.Get <IConnectionFrameworkSetup> ();

            switch (EffectiveType)
            {
            case StreamInstrumentationType.VerifyAsyncStreamCalls:
                instrumentation.RequireAsync = true;
                if (setup.UsingDotNet)
                {
                    instrumentation.AllowBeginEndAsync = true;
                    instrumentation.AllowSyncFlush     = true;
                }
                break;
            }

            if (Interlocked.CompareExchange(ref clientInstrumentation, instrumentation, null) != null)
            {
                throw new InternalErrorException();
            }

            LogDebug(ctx, 4, "CreateClientStream()");

            if (!HasFlag(InstrumentationFlags.ClientStream))
            {
                return(instrumentation);
            }

            instrumentation.OnNextRead(ReadHandler);

            return(instrumentation);

            async Task <int> ReadHandler(byte[] buffer, int offset, int size,
                                         StreamInstrumentation.AsyncReadFunc func,
                                         CancellationToken cancellationToken)
            {
                ctx.Assert(Client.Stream, Is.Not.Null);
                ctx.Assert(Client.SslStream, Is.Not.Null);
                ctx.Assert(Client.SslStream.IsAuthenticated, Is.False);

                switch (EffectiveType)
                {
                case StreamInstrumentationType.ClientHandshake:
                    LogDebug(ctx, 4, "CreateClientStream(): client handshake");
                    break;

                case StreamInstrumentationType.ReadDuringClientAuth:
                    await ctx.AssertException <InvalidOperationException> (ReadClient).ConfigureAwait(false);

                    break;

                case StreamInstrumentationType.ShortReadDuringClientAuth:
                    if (size <= 5)
                    {
                        instrumentation.OnNextRead(ReadHandler);
                    }
                    size = 1;
                    break;

                case StreamInstrumentationType.VerifyAsyncStreamCalls:
                    break;

                default:
                    throw ctx.AssertFail(EffectiveType);
                }

                return(await func(buffer, offset, size, cancellationToken));
            }

            Task <int> ReadClient()
            {
                const int bufferSize = 100;

                return(Client.Stream.ReadAsync(new byte[bufferSize], 0, bufferSize));
            }
        }
 public ExceptionMiddleware(IHostingEnvironment environment, RequestDelegate request)
 {
     _environment = environment;
     _logger      = DependencyInjector.GetService <ILogger>();
     _request     = request;
 }
 public ApplicationTest()
 {
     DependencyInjector.RegisterServices();
     DependencyInjector.AddDbContextInMemoryDatabase <DatabaseContext>();
     UserApplication = DependencyInjector.GetService <IUserApplication>();
 }
Example #26
0
 public ClassActivator(IDependencyLocator activator, DependencyInjector injector)
 {
     Activator = activator;
     Injector  = injector;
 }
Example #27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            DependencyInjector.Configure(services);
        }
Example #28
0
 public AppleCertificateHost(CertificateResourceType type)
 {
     CertificateAndKey = ResourceManager.GetCertificateWithKey(type);
     provider          = DependencyInjector.Get <IAppleCertificateProvider> ();
     AppleCertificate  = provider.GetAppleCertificate(CertificateAndKey);
 }
        public void Initialize()
        {
#if DEAD_CODE
            DependencyInjector.RegisterDependency <IAppleCertificateProvider> (() => new AppleCertificateProvider());
#endif
        }
Example #30
0
        public static SslStreamTestParameters GetParameters(TestContext ctx, ConnectionTestCategory category, ConnectionTestType type)
        {
            var certificateProvider = DependencyInjector.Get <ICertificateProvider> ();
            var acceptAll           = certificateProvider.AcceptAll();
            var rejectAll           = certificateProvider.RejectAll();
            var acceptNull          = certificateProvider.AcceptNull();
            var acceptSelfSigned    = certificateProvider.AcceptThisCertificate(ResourceManager.SelfSignedServerCertificate);
            var acceptFromLocalCA   = certificateProvider.AcceptFromCA(ResourceManager.LocalCACertificate);

            var name = GetTestName(category, type);

            switch (type)
            {
            case ConnectionTestType.Default:
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ClientCertificateValidator = acceptAll
                });

            case ConnectionTestType.AcceptFromLocalCA:
                return(new SslStreamTestParameters(category, type, name, ResourceManager.ServerCertificateFromCA)
                {
                    ClientCertificateValidator = acceptFromLocalCA
                });

            case ConnectionTestType.NoValidator:
                // The default validator only allows ResourceManager.SelfSignedServerCertificate.
                return(new SslStreamTestParameters(category, type, name, ResourceManager.ServerCertificateFromCA)
                {
                    ExpectClientException = true
                });

            case ConnectionTestType.RejectAll:
                // Explicit validator overrides the default ServicePointManager.ServerCertificateValidationCallback.
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ExpectClientException = true, ClientCertificateValidator = rejectAll
                });

            case ConnectionTestType.UnrequestedClientCertificate:
                // Provide a client certificate, but do not require it.
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ClientCertificate = ResourceManager.PenguinCertificate, ClientCertificateValidator = acceptSelfSigned,
                    ServerCertificateValidator = acceptNull
                });

            case ConnectionTestType.RequestClientCertificate:
                /*
                 * Request client certificate, but do not require it.
                 *
                 * FIXME:
                 * SslStream with Mono's old implementation fails here.
                 */
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ClientCertificate = ResourceManager.MonkeyCertificate, ClientCertificateValidator = acceptSelfSigned,
                    AskForClientCertificate = true, ServerCertificateValidator = acceptFromLocalCA
                });

            case ConnectionTestType.RequireClientCertificate:
                // Require client certificate.
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ClientCertificate = ResourceManager.MonkeyCertificate, ClientCertificateValidator = acceptSelfSigned,
                    AskForClientCertificate = true, RequireClientCertificate = true,
                    ServerCertificateValidator = acceptFromLocalCA
                });

            case ConnectionTestType.OptionalClientCertificate:
                /*
                 * Request client certificate without requiring one and do not provide it.
                 *
                 * To ask for an optional client certificate (without requiring it), you need to specify a custom validation
                 * callback and then accept the null certificate with `SslPolicyErrors.RemoteCertificateNotAvailable' in it.
                 *
                 * FIXME:
                 * Mono with the old TLS implementation throws SecureChannelFailure.
                 */
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ClientCertificateValidator = acceptSelfSigned, AskForClientCertificate = true,
                    ServerCertificateValidator = acceptNull
                });

            case ConnectionTestType.RejectClientCertificate:
                // Reject client certificate.
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ClientCertificate = ResourceManager.MonkeyCertificate, ClientCertificateValidator = acceptSelfSigned,
                    ServerCertificateValidator = rejectAll, AskForClientCertificate = true,
                    ExpectClientException = true, ExpectServerException = true
                });

            case ConnectionTestType.MissingClientCertificate:
                // Missing client certificate.
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ClientCertificateValidator = acceptSelfSigned,
                    AskForClientCertificate = true, RequireClientCertificate = true,
                    ExpectClientException = true, ExpectServerException = true
                });

            case ConnectionTestType.MustNotInvokeGlobalValidator:
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ClientCertificateValidator = acceptAll,
                    GlobalValidationFlags = GlobalValidationFlags.MustNotInvoke
                });

            case ConnectionTestType.MustNotInvokeGlobalValidator2:
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    GlobalValidationFlags = GlobalValidationFlags.MustNotInvoke,
                    ExpectClientException = true
                });

            case ConnectionTestType.SyncAuthenticate:
                return(new SslStreamTestParameters(category, type, name, ResourceManager.SelfSignedServerCertificate)
                {
                    ClientCertificateValidator = acceptAll, SslStreamFlags = SslStreamFlags.SyncAuthenticate
                });

            default:
                throw ctx.AssertFail("Invalid ConnectionTestType: `{0}'.", type);
            }
        }
 public MantenimientoFacturaElectronica()
 {
     Inicializador.Init();
     facturaElectronica = DependencyInjector.Retrieve <GenericRepository <ServicioFacturaElectronica> >();
     log = new ManejoErrores();
 }
Example #32
0
        public void TestGetObjectFromContainer()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig(), new ServiceConfigurationC());
            container.Reconfigure();
            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            IAggregate aggregate = container.GetObject<IAggregate>();
            Assert.IsNotNull(aggregate);

            var b = container.GetObject("SomeDomainCmdServiceB");
            Assert.IsNotNull(b);

            // If some instance uniquely implements interface but the object definition id is specified, can it still be retrieved through the interface??
            ISomeNewDomainCmdService newCmdService = container.GetObject<ISomeNewDomainCmdService>();
            Assert.IsNotNull(newCmdService);
            SomeNewDomainCmdService newCmdService2 = container.GetObject<SomeNewDomainCmdService>();
            Assert.IsNotNull(newCmdService2);
            var serviceD = container.GetObject<SomeDomainCmdServiceD>("D");

            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<ISomeDomainCmdService>());
            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<SomeDomainCmdServiceD>());
            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<SomeDomainCmdServiceD>("E"));
            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<INotImplementedInterface>());
        }
Example #33
0
        static bool IsMobile()
        {
            var support = DependencyInjector.Get <IPortableSupport> ();

            return(support.IsMobile);
        }
Example #34
0
        public void ShouldCreateATreeWithStructs()
        {
            StructTree tree = new DependencyInjector().CreateAndInjectDependencies <StructTree>().rootBean;

            Assert.IsNotNull(tree.structChild);
        }
Example #35
0
 public AppleCertificateHost(X509Certificate certificate)
 {
     CertificateAndKey = certificate;
     provider          = DependencyInjector.Get <IAppleCertificateProvider> ();
     AppleCertificate  = provider.GetAppleCertificate(CertificateAndKey);
 }
Example #36
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
     DependencyInjector.RegisterServices(services);
     SwaggerConfig.AddSwagger(services);
 }
Example #37
0
 protected override void Start()
 {
     base.Start();
     m_InputOverride = AtfInput.BASE_INPUT;
     DependencyInjector.InjectType(m_InputOverride.GetType());
 }
Example #38
0
        public void GivenCreate_WhenConfigurationIsNotSpecified_ThenThrowsArgumentException()
        {
            var dependencyInjector = new DependencyInjector();

            Assert.Throws <ArgumentException>(() => dependencyInjector.Create <IBasicClass>());
        }
 public static void AddDependencyInjectionCustom(this IServiceCollection services, IConfiguration configuration)
 {
     DependencyInjector.RegisterServices(services);
     DependencyInjector.AddDbContext <DatabaseContext>(configuration.GetConnectionString(nameof(DatabaseContext)));
     DependencyInjector.GetService <DatabaseContext>().Seed();
 }
Example #40
0
        public IEncryptionTestHost CreateInstance(TestContext context)
        {
            var provider = DependencyInjector.Get <ICryptoProvider> ();

            return(provider.GetEncryptionTestHost(ProviderType, GetParameters()));
        }
Example #41
0
 public void Init()
 {
     mockNetworkClient = new MockNetworkClient();
     // Replace the real networkClient with mock object, it will be injected later into FirstScreen component
     DependencyInjector.ReplaceComponent <NetworkClient>(mockNetworkClient);
 }
        private Tuple <DependencyInjector, DependencyInjector, DependencyInjector> GetNewClassInjector(IActivatorTree tree)
        {
            var type = tree.Key.ReturnType;

            if (type.IsAbstract)
            {
                throw new Exception("Unable to locate Abstract class : " + type.Name);
            }
            if (type.IsInterface)
            {
                throw new Exception("Unable to locate Interface : " + type.Name);
            }

            DependencyInjector activator      = null;
            DependencyInjector activatorCtor  = null;
            DependencyInjector activatorAfter = null;


            var types = new Stack <Type>();
            var t     = type;


            while (t != null)
            {
                types.Push(t);
                t = t.BaseType;
            }

            while (types.Count > 0)
            {
                t = types.Pop();
                foreach (var p in t.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    foreach (var attr in p.GetCustomAttributes <ImportAttribute>())
                    {
                        var ctx = ImportContext.Get(type, p).Get(typeof(IActivator));
                        var l   = GetLocator(new ActivatorTree(tree, ctx));
                        var a   = (IActivator)(l(RuntimeImportContext.GetStatic(null, ctx), null));

                        if (p is ConstructorInfo ci)
                        {
                            activatorCtor = a.GetActivator(GetLocator, new ActivatorTree(tree, ImportContext.Get(type, p)));
                        }
                        else
                        {
                            switch (attr.Location)
                            {
                            case InjectLocation.BeforeConstructor:
                                activator += a.GetActivator(GetLocator, new ActivatorTree(tree, ImportContext.Get(type, p)));
                                break;

                            case InjectLocation.AfterConstructor:
                                activatorAfter += a.GetActivator(GetLocator, new ActivatorTree(tree, ImportContext.Get(type, p)));
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }


            if (typeof(IInitializer).IsAssignableFrom(type))
            {
                activator += (ctx, args, o) => _initializerMethodInfo.Invoke(o, new object [] { ctx, args });
            }

            foreach (var k in _initializers)
            {
                if (k.Key.IsAssignableFrom(type))
                {
                    foreach (var action in k.Value)
                    {
                        activator += action;
                    }
                }
            }

            return(new Tuple <DependencyInjector, DependencyInjector, DependencyInjector>(activator, activatorCtor, activatorAfter));
        }
Example #43
0
        static SimpleConnectionParameters Create(TestContext ctx, InstrumentationCategory category, SimpleConnectionType type)
        {
            var parameters = CreateParameters(category, type);

            var provider         = DependencyInjector.Get <ICertificateProvider> ();
            var acceptSelfSigned = provider.AcceptThisCertificate(ResourceManager.SelfSignedServerCertificate);
            var acceptFromCA     = provider.AcceptFromCA(ResourceManager.LocalCACertificate);

            switch (type)
            {
            case SimpleConnectionType.Simple:
                break;

            case SimpleConnectionType.ValidateCertificate:
                parameters.ServerCertificate          = ResourceManager.ServerCertificateFromCA;
                parameters.ClientCertificateValidator = acceptFromCA;
                break;

            case SimpleConnectionType.SimpleTls10:
                parameters.ProtocolVersion = ProtocolVersions.Tls10;
                break;

            case SimpleConnectionType.SimpleTls11:
                parameters.ProtocolVersion = ProtocolVersions.Tls11;
                parameters.ExpectedCipher  = CipherSuiteCode.TLS_DHE_RSA_WITH_AES_256_CBC_SHA;
                break;

            case SimpleConnectionType.SimpleTls12:
                parameters.ProtocolVersion = ProtocolVersions.Tls12;
                parameters.ExpectedCipher  = CipherSuiteCode.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384;
                break;

            case SimpleConnectionType.SelectCiphersTls10:
                parameters.ProtocolVersion = ProtocolVersions.Tls10;
                break;

            case SimpleConnectionType.SelectCiphersTls11:
                parameters.ProtocolVersion = ProtocolVersions.Tls11;
                break;

            case SimpleConnectionType.SelectCiphersTls12:
                parameters.ProtocolVersion = ProtocolVersions.Tls12;
                break;

            case SimpleConnectionType.RequestClientCertificate:
                /*
                 * Request client certificate, but do not require it.
                 *
                 * FIXME:
                 * SslStream with Mono's old implementation fails here.
                 */
                parameters.ClientCertificate          = ResourceManager.MonkeyCertificate;
                parameters.ClientCertificateValidator = acceptSelfSigned;
                parameters.AskForClientCertificate    = true;
                parameters.ServerCertificateValidator = acceptFromCA;
                break;

            case SimpleConnectionType.RequireClientCertificateRSA:
                /*
                 * Require client certificate.
                 *
                 */
                parameters.ClientCertificate          = ResourceManager.MonkeyCertificate;
                parameters.ClientCertificateValidator = acceptSelfSigned;
                parameters.RequireClientCertificate   = true;
                parameters.ServerCertificateValidator = acceptFromCA;
                parameters.ServerCiphers = new CipherSuiteCode[] { CipherSuiteCode.TLS_RSA_WITH_AES_128_CBC_SHA };
                break;

            case SimpleConnectionType.RequireClientCertificateDHE:
                /*
                 * Require client certificate.
                 *
                 */
                parameters.ClientCertificate          = ResourceManager.MonkeyCertificate;
                parameters.ClientCertificateValidator = acceptSelfSigned;
                parameters.RequireClientCertificate   = true;
                parameters.ServerCertificateValidator = acceptFromCA;
                parameters.ServerCiphers = new CipherSuiteCode[] { CipherSuiteCode.TLS_DHE_RSA_WITH_AES_256_CBC_SHA };
                break;

            case SimpleConnectionType.CipherSelectionOrder:
                parameters.ProtocolVersion = ProtocolVersions.Tls12;
                parameters.ClientCiphers   = new CipherSuiteCode[] {
                    CipherSuiteCode.TLS_RSA_WITH_AES_128_CBC_SHA, CipherSuiteCode.TLS_DHE_RSA_WITH_AES_128_CBC_SHA
                };
                parameters.ExpectedServerCipher = CipherSuiteCode.TLS_RSA_WITH_AES_128_CBC_SHA;
                break;

            case SimpleConnectionType.CipherSelectionOrder2:
                parameters.ProtocolVersion = ProtocolVersions.Tls12;
                parameters.ClientCiphers   = new CipherSuiteCode[] {
                    CipherSuiteCode.TLS_DHE_RSA_WITH_AES_128_CBC_SHA, CipherSuiteCode.TLS_RSA_WITH_AES_128_CBC_SHA
                };
                parameters.ExpectedServerCipher = CipherSuiteCode.TLS_DHE_RSA_WITH_AES_128_CBC_SHA;
                break;

            case SimpleConnectionType.MartinTest:
                goto case SimpleConnectionType.SimpleTls12;

            default:
                ctx.AssertFail("Unsupported connection type: '{0}'.", type);
                break;
            }

            return(parameters);
        }
        public void Initializer(Type type, DependencyInjector action)
        {
            var list = _initializers.GetOrAdd(type, t => new List <DependencyInjector>());

            list.Add(action);
        }
Example #45
0
 public void Initialize()
 {
     DependencyInjector.RegisterDependency <WebTestFeatures> (() => new WebTestFeatures());
 }
Example #46
0
        static void Main()
        {
            DependencyInjector injector = new DependencyInjector();

            RunApplication(injector.container);
        }
Example #47
0
 public DiServiceHostFactoryIntegration(DependencyInjector container)
 {
     DiServiceHostFactoryIntegration.container = container;
 }
 public HashTest()
 {
     DependencyInjector.RegisterServices();
     Hash = DependencyInjector.GetService <IHash>();
 }