Example #1
0
        private void AddClassMaps(Type sourceType, Type targetType)
        {
            if (!ClassMaps.Any(item => item.SourceType == sourceType && item.TargetType == targetType))
            {
                ClassMap classMap = new ClassMap(sourceType, targetType);

                ClassMaps.Add(classMap);

                foreach (PropMap propMap in classMap.PropMaps.Where(x => x.IsComposite))
                {
                    if (typeof(IEnumerable).IsAssignableFrom(propMap.SourceProp.Type))
                    {
                        if (propMap.SourceProp.Type.IsGenericType)
                        {
                            AddClassMaps(propMap.SourceProp.Type.GetGenericArguments()[0], propMap.TargetProp.Type.GetGenericArguments()[0]);
                        }
                        else if (propMap.SourceProp.Type.IsArray)
                        {
                            AddClassMaps(propMap.SourceProp.Type.GetElementType(), propMap.TargetProp.Type.GetElementType());
                        }
                    }
                    else
                    {
                        AddClassMaps(propMap.SourceProp.Type, propMap.TargetProp.Type);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Gets the class map registered for an object of the given type.
        /// </summary>
        /// <param name="classType">The type of the object to get the class map for.</param>
        /// <param name="classMap">The class map for the given type if it exists, else null.</param>
        /// <returns>True if a class map exists for the given type, else false.</returns>
        public bool TryGetClassMap(Type classType, out IMap classMap)
        {
            if (classType == null)
            {
                throw new ArgumentNullException(nameof(classType));
            }

            return(ClassMaps.TryGetValue(classType, out classMap));
        }
        public static IFixture CreateFixture()
        {
            ConventionPacks.Register();
            ClassMaps.Register();

            var configuration = Configuration.GetConfiguration();
            var container     = Bootstrapper.ConfigureContainer(configuration, LoggerFactory.Create(configuration));
            var fixture       = new Fixture();

            fixture.Customize <ContainerSpecimenBuilder>(composer => new ContainerSpecimenBuilder(container));
            fixture.Register(ObjectId.GenerateNewId);
            return(fixture);
        }
        public static void Main(string[] args)
        {
            ConventionPacks.Register();
            ClassMaps.Register();

            var configuration = Configuration.GetConfiguration(args);

            using (var logger = LoggerFactory.Create(configuration))
                using (var container = Bootstrapper.ConfigureContainer(configuration, logger))
                {
                    BuildWebHost(container, logger, configuration, args).Build().Run();
                }
        }
Example #5
0
        /// <summary>
        /// Registers the given class map to be used when mapping a row to an object.
        /// </summary>
        /// <param name="classType">The type of the class.</param>
        /// <param name="classMap">The class map to use.</param>
        public void RegisterClassMap(Type classType, IMap classMap)
        {
            if (classType == null)
            {
                throw new ArgumentNullException(nameof(classType));
            }
            if (classMap == null)
            {
                throw new ArgumentNullException(nameof(classMap));
            }
            if (ClassMaps.ContainsKey(classType))
            {
                throw new ExcelMappingException($"Class map already exists for type \"{classType.FullName}\"");
            }

            ClassMaps.Add(classType, classMap);
        }
        public static IFixture CreateFixture()
        {
            ConventionPacks.Register();
            ClassMaps.Register();

            var configuration = Configuration.GetConfiguration();
            var container     = new Container();

            var mongoUrl = configuration["mongo:url"];
            var url      = new MongoUrl(mongoUrl);
            var client   = new MongoClient(url);
            var database = client.GetDatabase(url.DatabaseName);

            container.RegisterInstance(database);

            var fixture = new Fixture();

            fixture.Customize <ContainerSpecimenBuilder>(composer => new ContainerSpecimenBuilder(container));
            fixture.Register(ObjectId.GenerateNewId);
            return(fixture);
        }
        private static async Task Main(string[] args)
        {
            ConventionPacks.Register();
            ClassMaps.Register();

            var configuration = Configuration.GetConfiguration(args);

            using (var logger = LoggerFactory.Create(configuration))
                using (var container = Bootstrapper.ConfigureContainer(configuration, logger))
                {
                    try
                    {
                        logger.Information("Starting");

                        var host = new HostBuilder()
                                   .ConfigureHostConfiguration(builder => builder.Configure())
                                   .ConfigureServices((context, services) =>
                                                      services.AddSingleton(_ => container.GetAllInstances <IHostedService>()))
                                   .Build();

                        container.Register(() => host.Services.GetRequiredService <IApplicationLifetime>());
                        container.Verify();

                        using (host)
                        {
                            await host.StartAsync();

                            logger.Information("Started");
                            await host.WaitForShutdownAsync();
                        }
                    }
                    catch (Exception e)
                    {
                        logger.Fatal(e, "Event publisher crashed.");
                    }

                    logger.Information("Stopped");
                }
        }