예제 #1
0
        public void CreateMapping <TSource, TTarget>()
        {
            var key = new MappingKey(typeof(TSource), typeof(TTarget));

            if (Builders.ContainsKey(key))
            {
                throw new MappingAlreadyExistsException("Another mapping already exists with the supplied types");
            }

            var builder = new MappingBuilder <TSource, TTarget>(this);

            builder.CreateDefaultBindings();

            Builders.Add(key, builder);
            BuilderDescriptors.Add(new BuilderDescriptor(typeof(TSource), typeof(TTarget), builder.Dependencies, true));
        }
예제 #2
0
        public void CreateMapping <TSource, TTarget, TParam>(Action <IMappingBuilder <TSource, TTarget, TParam> > mappingFactory)
        {
            var key = new MappingKey(typeof(TSource), typeof(TTarget), typeof(TParam));

            if (ParametrizedBuilders.ContainsKey(key))
            {
                throw new MappingAlreadyExistsException("Another mapping already exists with the supplied types");
            }

            var builder = new MappingBuilder <TSource, TTarget, TParam>(this);

            mappingFactory(builder);
            builder.CreateDefaultBindings(); // Should be run after the explicit mappings

            ParametrizedBuilders.Add(key, new ParametrizedBuilderDescriptor
            {
                Mapping = new Mapping <TSource, TTarget, TParam> {
                    Builder = builder
                },
                Builder = builder
            });
        }