Exemplo n.º 1
0
        public Glossary CreateGlossary(string domainAssembly)
        {
            var types = _fileLoader.GetTypesFromAssembly(domainAssembly);

            var glossary = new Glossary();

            foreach (var t in types)
            {
                var attributes = t.GetCustomAttributes(true);
                if (attributes.Any(a => a is AggregateRoot))
                {
                    var aggregateRootTerm  = attributes.OfType <AggregateRoot>().First();
                    var module             = glossary.CreateOrGetModuleFrom(aggregateRootTerm);
                    var aggregateRootModel = new AggregateRootModel {
                        Name = aggregateRootTerm.Name, Definition = aggregateRootTerm.Definition
                    };

                    aggregateRootModel.Entities.AddRange(GetEntitiesFromProperties(t));
                    aggregateRootModel.ValueObjects.AddRange(GetValueObjectsFromProperties(t));
                    aggregateRootModel.CommandMethods.AddRange(GetCommandMethods(t));

                    module.Aggregates.Add(aggregateRootModel);
                }
                else if (attributes.Any(a => a is Entity))
                {
                    var entityTerm  = attributes.OfType <Entity>().First();
                    var module      = glossary.CreateOrGetModuleFrom(entityTerm);
                    var entityModel = new EntityModel {
                        Name = entityTerm.Name, Definition = entityTerm.Definition
                    };

                    entityModel.ValueObjects.AddRange(GetValueObjectsFromProperties(t));
                    entityModel.CommandMethods.AddRange(GetCommandMethods(t));

                    module.Entities.Add(entityModel);
                }
                else if (attributes.Any(a => a is ValueObject))
                {
                    var valueObjectTerm  = attributes.OfType <ValueObject>().First();
                    var module           = glossary.CreateOrGetModuleFrom(valueObjectTerm);
                    var valueObjectModel = new ValueObjectModel {
                        Name = valueObjectTerm.Name, Definition = valueObjectTerm.Definition
                    };

                    module.ValueObjects.Add(valueObjectModel);
                }
                else if (attributes.Any(a => a is DomainService))
                {
                    var domainServiceTerm  = attributes.OfType <DomainService>().First();
                    var module             = glossary.CreateOrGetModuleFrom(domainServiceTerm);
                    var domainServiceModel = new DomainServiceModel {
                        Name = domainServiceTerm.Name, Definition = domainServiceTerm.Definition
                    };

                    module.DomainServices.Add(domainServiceModel);
                }
                else if (attributes.Any(a => a is DomainEvent))
                {
                    var domainEventTerm  = attributes.OfType <DomainEvent>().First();
                    var module           = glossary.CreateOrGetModuleFrom(domainEventTerm);
                    var domainEventModel = new DomainEventModel {
                        Name = domainEventTerm.Name, Definition = domainEventTerm.Definition
                    };

                    module.DomainEvents.Add(domainEventModel);
                }
            }

            return(glossary);
        }