Exemple #1
0
            /// <summary>
            /// Gets the builder for the given Id
            /// </summary>
            /// <param name="id">The identifier.</param>
            /// <returns></returns>
            public IEntityBuilder Get(Id id)
            {
                BuilderInfo builder;

                if (id != Guid.Empty && !Ids.ContainsKey(id))
                {
                    Ids.Add(id, id);
                }
                if (Builders.TryGetValue(id, out builder))
                {
                    return(builder.Builder);
                }

                // Add the Entity to the mapper to make sure it can be created in the correct order
                EntityDependency.Mapper.Add(id);

                // Get the default Builder, or if no builder is defined, create a Generic Builder
                var constructor = (BuilderConstructorForEntity.ContainsKey(id) ? BuilderConstructorForEntity[id] : GetGenericConstructor(id));

                builder = new BuilderInfo(id, (IEntityBuilder)constructor.Invoke(new object[] { id }));

                // Apply any Custom Actions
                ApplyCustomActions(id, builder);

                // Add the Builder to both Dictionaries (keyed by Id and Logical Name)
                BuildersByEntityType.AddOrAppend(id, builder);
                Builders.Add(id, builder);

                return(builder.Builder);
            }
Exemple #2
0
            /// <summary>
            /// Creates a GenericEntityBuilder of the type of logical name being passed in.  Employs locking since BuilderForEntity is static
            /// </summary>
            /// <param name="logicalName">Name of the Entity to create a GenericEntityBuilder Constructor For.</param>
            /// <returns></returns>
            private ConstructorInfo GetGenericConstructor(string logicalName)
            {
                ConstructorInfo constructor;

                if (BuilderConstructorForEntity.TryGetValue(logicalName, out constructor))
                {
                    return(constructor);
                }

                lock (BuilderConstructorForEntityLock)
                {
                    if (BuilderConstructorForEntity.TryGetValue(logicalName, out constructor))
                    {
                        return(constructor);
                    }

                    var builder = typeof(GenericEntityBuilder <>).MakeGenericType(TestBase.GetType(logicalName));
                    constructor = builder.GetConstructor(new[] { typeof(Id) });
                    BuilderConstructorForEntity.Add(logicalName, constructor);
                    return(constructor);
                }
            }