Beispiel #1
0
        protected override void Load(ContainerBuilder builder)
        {
            var assemblies = AssemblyTypeResolver.GetAllAssembliesFromAppDomain().ToArray();

            builder.RegisterAssemblyTypes(assemblies)
            .AsClosedTypesOf(typeof(ScenarioFor <>));
            builder.RegisterAssemblyTypes(assemblies)
            .AsClosedTypesOf(typeof(ScenarioFor <,>));

            //builder.RegisterGeneric(typeof (ScenarioFor<>)).InstancePerLifetimeScope();
            //builder.RegisterGeneric(typeof (ScenarioFor<,>)).InstancePerLifetimeScope();

            var mockFactory = new MockDetector().FindAvailableMock();

            if (mockFactory == null)
            {
                builder.Register(c => new IocContainer(c.Resolve <ILifetimeScope>()))
                .As <IContainer>()
                .InstancePerLifetimeScope();
            }
            else
            {
                builder.Register(c => new AutoMockingContainer(mockFactory()))
                .As <IContainer>()
                .InstancePerLifetimeScope();
            }
        }
Beispiel #2
0
        public static IServiceCollection AddCybtansServices(this IServiceCollection services, params Assembly[] assemblies)
        {
            AssemblyTypeResolver resolver = new AssemblyTypeResolver(assemblies);

            resolver.Init();

            foreach (var kv in resolver.Dependencies)
            {
                var contract = kv.Key;
                var info     = kv.Value;

                switch (info.LifeType)
                {
                case LifeType.Transient:
                    services.TryAddTransient(contract, info.Type);
                    break;

                case LifeType.Scope:
                    services.TryAddScoped(contract, info.Type);
                    break;

                case LifeType.Singleton:
                    services.TryAddSingleton(contract, info.Type);
                    break;
                }
            }

            return(services);
        }
Beispiel #3
0
        private void RegisterScenarios(ContainerBuilder builder)
        {
            var assemblies = AssemblyTypeResolver.GetAllAssembliesFromAppDomain().ToArray();

            builder.RegisterAssemblyTypes(assemblies)
            .AsClosedTypesOf(typeof(ScenarioFor <>));
            builder.RegisterAssemblyTypes(assemblies)
            .AsClosedTypesOf(typeof(ScenarioFor <,>));
        }
        private void RegisterScenarios(TinyIoCContainer container)
        {
            var scenarios = AssemblyTypeResolver
                            .GetAllTypesFromAppDomain()
                            .Where(type => type.IsScenario() && !type.IsAbstract)
                            .ToList();

            container.RegisterMultiple <IScenario>(scenarios);
            this.Log().DebugFormat("Registered {RegisteredScenarioCount} Scenarios", scenarios.Count);
        }
Beispiel #5
0
        public void DefaultAssemblyTypeResolver()
        {
            var assembly = Assembly.LoadFrom(Path.Combine(Environment.CurrentDirectory, "CSharpToJs.Tests.dll"));
            var resolver = new AssemblyTypeResolver(assembly, "CSharpToJs.Tests.Mocks", null);

            var types = resolver.Resolve();

            Assert.Contains(typeof(DummyClass), types);
            Assert.DoesNotContain(typeof(IgnoredClass), types);
        }
Beispiel #6
0
        public override void Load()
        {
            var scenarios = AssemblyTypeResolver
                            .GetAllTypesFromAppDomain()
                            .Where(type => type.IsScenario() && !type.IsAbstract);

            foreach (var scenario in scenarios)
            {
                Bind(scenario).ToSelf();
            }
        }
Beispiel #7
0
        static SpecifyConfiguration Configure()
        {
            var customConvention = AssemblyTypeResolver
                                   .GetAllTypesFromAppDomain()
                                   .FirstOrDefault(type => typeof(SpecifyConfiguration).IsAssignableFrom(type) && type.IsClass);
            var config = customConvention != null
                ? (SpecifyConfiguration)Activator.CreateInstance(customConvention)
                : new SpecifyConfiguration();

            Configurator.Scanners.StoryMetadataScanner = () => new SpecifyStoryMetadataScanner();
            if (config.LoggingEnabled)
            {
                Configurator.Processors.Add(() => new LoggingProcessor());
            }

            return(config);
        }
Beispiel #8
0
        public void WriteAndReadEmptyDictionary()
        {
            var dict = new Dictionary<string, object>();
            var typeResolver = new AssemblyTypeResolver(typeof(int).Assembly);

            var sb = new StringBuilder();
            using (var writer = XmlWriter.Create(sb, null)) {
                writer.WriteStartElement("dict");
                writer.WriteDictionary(dict, typeResolver);
                writer.WriteEndElement();
            }

            using (var reader = XmlReader.Create(new StringReader(sb.ToString()))) {
                reader.ReadToDescendant("dict");
                var result = reader.ReadDictionary<object>(typeResolver);
                Assert.AreEqual(result.Count, 0);
            }
        }
Beispiel #9
0
        public AutofacDependencyResolver()
        {
            var assemblies = AssemblyTypeResolver.GetAllAssembliesFromAppDomain().ToArray();

            _containerBuilder.RegisterAssemblyModules(assemblies);
        }
Beispiel #10
0
 /// <inheritdoc />
 public IEnumerable <Type> GetAllTypesFromAppDomain()
 {
     return(AssemblyTypeResolver.GetAllTypesFromAppDomain());
 }
Beispiel #11
0
 public NinjectDependencyResolver()
 {
     var assemblies = AssemblyTypeResolver.GetAllAssembliesFromAppDomain().ToArray();
     // how to register all modules in Ninject
     //_containerBuilder.RegisterAssemblyModules(assemblies);
 }