示例#1
0
 public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
 {
     if (type is InputModel inputModel && model is ClassModel @class)
     {
         GenerateInputModel(registry, inputModel, @class);
     }
 }
示例#2
0
 public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
 {
     if (type is ViewModel viewModel && model is ClassModel @class)
     {
         GenerateViewModel(registry, viewModel, @class);
     }
 }
示例#3
0
 public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
 {
     if (type is Command command && model is ClassModel @class)
     {
         @class.WithBaseType(SystemTypes.Command());
     }
 }
示例#4
0
        public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
        {
            if (type is DomainEvent domainEvent && model is ClassModel @class)
            {
                @class = @class
                         .WithBaseType(SystemTypes.DomainEvent(@class))
                         .WithAttributes(SystemTypes.Parse("Serializable"));

                // Generate property for aggregate unique id
                if (domainEvent.Aggregate.UniqueIdentifier != null)
                {
                    @class.AddDomainProperty(new Property {
                        Name        = domainEvent.Aggregate.Name,
                        Description = "Unique id of aggregate that throws this event",
                        Type        = new MetaType
                        {
                            Type = domainEvent.Aggregate
                        }
                    }, registry);
                }


                // Generate properties
                foreach (var p in domainEvent.Properties)
                {
                    @class.AddDomainProperty(p, registry);
                }

                // Generate constructor
                @class.AddConstructor()
                .WithPropertyParameters()
                .WithAttributes(SystemTypes.JsonConstructorAttribute())
                .WithBody(builder => { builder.AssignPropertiesFromParameters(); });
            }
        }
示例#5
0
 private static void BuildDomainEventPublisher(ITypeModelRegistry registry, BodyBuilder builder, Aggregate aggregate, ClassModel @class, ClassModel domainEvent, List <MethodParameter> parameters)
 {
     if (aggregate.UniqueIdentifier != null)
     {
         if (aggregate.UniqueIdentifier.Type.Resolve(registry) != SystemTypes.Guid)
         {
             builder.InvokeMethod(
                 SystemTypes.DomainEventPublishMethodName,
                 domainEvent.Construct(
                     parameters.ToExpressions(),
                     domainEvent.Initializer(SystemTypes.DomainEventAggregateRootIdentifierName, @class.GetMethod("ToGuid").Invoke(parameters.First().Expression)))
                 );
         }
         else
         {
             builder.InvokeMethod(
                 SystemTypes.DomainEventPublishMethodName,
                 domainEvent.Construct(
                     parameters.ToExpressions(),
                     domainEvent.Initializer(SystemTypes.DomainEventAggregateRootIdentifierName, parameters.First().Expression))
                 );
         }
     }
     else
     {
         builder.InvokeMethod(SystemTypes.DomainEventPublishMethodName, domainEvent.Construct(parameters.ToExpressions().ToArray()));
     }
 }
示例#6
0
        public static TypeModel GetDomainType(this MetaParameter parameter, ITypeModelRegistry registry)
        {
            TypeModel parameterType;

            if (parameter.Type.Type is Aggregate aggregate && aggregate.UniqueIdentifier != null)
            {
                parameterType = aggregate.UniqueIdentifier.Type.Resolve(registry);
            }
示例#7
0
        public static TypeModel GetDomainType(this Property property, ITypeModelRegistry registry)
        {
            TypeModel propertyType;

            if (property.Type.Type is Aggregate aggregate && aggregate.UniqueIdentifier != null)
            {
                propertyType = aggregate.UniqueIdentifier.Type.Resolve(registry);
            }
示例#8
0
 public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
 {
     if (type is Enumeration e && model is EnumerationModel enumeration)
     {
         foreach (var literal in e.Literals)
         {
             enumeration.AddLiteral(literal);
         }
     }
 }
示例#9
0
 public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
 {
     if (type is Value value && model is ClassModel @class)
     {
         foreach (var p in value.Properties)
         {
             @class.AddDomainProperty(p, registry);
         }
     }
 }
示例#10
0
 private static IEnumerable <MethodParameter> GenerateDomainEventParameters(ITypeModelRegistry registry, DomainEvent de, Aggregate aggregate, bool includeUniqueId = true)
 {
     if (aggregate.UniqueIdentifier != null && includeUniqueId)
     {
         yield return(new MethodParameter(aggregate.UniqueIdentifier.Name.ToCamelCase(), aggregate.UniqueIdentifier.Type.Resolve(registry)));
     }
     foreach (var property in de.Properties)
     {
         yield return(new MethodParameter(property.GetDomainName().ToCamelCase(), property.GetDomainType(registry)));
     }
 }
示例#11
0
 public static TypeModel Resolve(this MetaType type, ITypeModelRegistry registry, string layer = "Domain")
 {
     if (type.SystemType != null)
     {
         return(SystemTypes.Parse(type.SystemType));
     }
     else
     {
         return(registry.Resolve(layer, type.Type) ?? SystemTypes.Parse(type.Name));
     }
 }
示例#12
0
 public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
 {
     if (type is Query query && model is ClassModel @class && query.Result is ViewModel viewModel)
     {
         @class = @class.WithBaseType(SystemTypes.Query(registry.Resolve(Layer, viewModel)));
         foreach (var property in query.Properties)
         {
             @class.AddDomainProperty(property, registry);
         }
     }
 }
 private static void AddViewModelProperty(ITypeModelRegistry registry, ClassModel @class, Property property)
 {
     if (property.Type.Type is Aggregate aggregate && aggregate.UniqueIdentifier != null)
     {
         @class.AddViewModelProperty(new Property
         {
             Name         = property.IsCollection ? property.Name : $"{property.Name}{aggregate.UniqueIdentifier.Name}",
             IsCollection = property.IsCollection,
             Type         = aggregate.UniqueIdentifier.Type
         }.Denormalized(), registry);
     }
示例#14
0
        public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
        {
            if (type is Service service && model is InterfaceModel @interface)
            {
                foreach (var method in service.Methods)
                {
                    var serviceMethod = @interface.AddMethod(method.Name)
                                        .WithParameters(method.Parameters.Select(p => GenerateMethodParameter(registry, p)).ToArray());

                    serviceMethod = serviceMethod.WithReturnType(SystemTypes.Task(GenerateReturnType(registry, method)));
                }
            }
        }
 private void GenerateViewModel(ITypeModelRegistry registry, ViewModel viewModel, ClassModel @class)
 {
     foreach (var property in viewModel.Properties)
     {
         AddViewModelProperty(registry, @class, property);
     }
     if (viewModel.Target != null)
     {
         foreach (var property in viewModel.Target.Properties)
         {
             AddViewModelProperty(registry, @class, property);
         }
     }
 }
示例#16
0
 private void GenerateInputModel(ITypeModelRegistry registry, InputModel inputModel, ClassModel @class)
 {
     foreach (var property in inputModel.Properties)
     {
         @class.AddDomainProperty(property.Denormalized(), registry);
     }
     if (inputModel.Source != null)
     {
         foreach (var property in inputModel.Source.Properties)
         {
             @class.AddDomainProperty(property.Denormalized(), registry);
         }
     }
 }
示例#17
0
 private void GenerateViewModel(ITypeModelRegistry registry, ViewModel viewModel, ClassModel @class)
 {
     foreach (var property in viewModel.Properties)
     {
         @class.AddViewModelProperty(property.Denormalized(), registry);
     }
     if (viewModel.Target != null)
     {
         foreach (var property in viewModel.Target.Properties)
         {
             @class.AddViewModelProperty(property.Denormalized(), registry);
         }
     }
 }
示例#18
0
        public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
        {
            if (type is Query query && model is ClassModel @class && query.Result is ViewModel viewModel)
            {
                var queryType       = registry.Resolve(Layer, query);
                var queryResultType = registry.Resolve(Layer, viewModel);

                @class = @class.WithImplementedInterfaces(SystemTypes.QueryHandler(queryType, queryResultType));

                var handler = @class.AddMethod("Handle")
                              .WithParameters(new MethodParameter("query", queryType))
                              .WithReturnType(queryResultType)
                              .WithBody(builder => { builder.ThrowNotImplemented(); });
            }
        }
示例#19
0
        public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
        {
            if (type is Command command && model is ClassModel @class)
            {
                var serviceInterface = registry.Resolve(Layer, command.Service, $"I{command.Service.Name}");

                var commandType = registry.Resolve(Layer, command);

                @class = @class.WithImplementedInterfaces(SystemTypes.CommandHandler(commandType));

                @class.AddProperty(command.Service.Name, serviceInterface).MakeReadOnly();

                @class.AddConstructor()
                .WithPropertyParameters()
                .WithBody(builder =>
                {
                    builder.AssignPropertiesFromParameters();
                });

                var handler = @class.AddMethod("HandleAsync")
                              .WithParameters(new MethodParameter("command", commandType))
                              .WithReturnType(SystemTypes.Task(SystemTypes.CommandResponse()))
                              .WithBody(builder =>
                {
                    if (command.ServiceMethod != null)
                    {
                        var method = command.Service.Methods.SingleOrDefault(m => m.Name == command.ServiceMethod);

                        if (method != null)
                        {
                            //TODO: execute service method en return command response with domain events
                            builder.ThrowNotImplemented();
                        }
                        else
                        {
                            builder.ThrowNotImplemented();
                        }
                    }
                    else
                    {
                        builder.ThrowNotImplemented();
                    }
                });
            }
        }
示例#20
0
        private static TypeModel GenerateReturnType(ITypeModelRegistry registry, MetaMethod method)
        {
            TypeModel returnType = null;

            if (method.Return != null)
            {
                if (method.Return.Type.Type is Aggregate && !method.Return.IsCollection)
                {
                    returnType = SystemTypes.Enumerable(SystemTypes.DomainEvent());
                }
                else
                {
                    returnType = method.Return.GetDomainType(registry);
                }
            }

            return(returnType);
        }
示例#21
0
        public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
        {
            if (type is Service service && model is ClassModel @class)
            {
                var @interface = registry.Resolve(Layer, type, $"I{type.Name}") as InterfaceModel;

                @class = @class.WithImplementedInterfaces(@interface);

                foreach (var method in @interface.Methods)
                {
                    @class.AddMethod(method.Name).WithParameters(method.Parameters.ToArray())
                    .WithReturnType(method.ReturnType);
                }


                var constructorParameters = new List <MethodParameter>();

                // Create property for aggregate repository
                if (service.AggregateRepository != null)
                {
                    var repositoryType = SystemTypes.Repository(registry.Resolve("Domain", service.AggregateRepository));

                    var property = @class.AddProperty($"{service.AggregateRepository.Name}Repository", repositoryType)
                                   .MakeReadOnly();

                    constructorParameters.Add(new MethodParameter(property.Name.ToCamelCase(), repositoryType));
                }

                // Create properties for query repositories
                if (service.QueryRepositories.Any())
                {
                    var databaseContext  = registry.Resolve("Infrastructure", service.Module);
                    var databaseProperty = @class.AddProperty($"Database", databaseContext)
                                           .MakeReadOnly();

                    constructorParameters.Add(new MethodParameter(databaseProperty.Name.ToCamelCase(), databaseContext));

                    foreach (var aggregate in service.QueryRepositories)
                    {
                        @class.AddProperty($"{aggregate.Name}Query", SystemTypes.Queryable(registry.Resolve("Infrastructure", aggregate)))
                        .WithGetter(builder =>
                        {
                            builder.Return(databaseProperty.AccessProperty($"{aggregate.Name}Set"));
                        })
                        .WithoutSetter();
                    }
                }

                // Create properties for services
                foreach (var s in service.Services)
                {
                    var serviceType = registry.Resolve(Layer, s, $"I{s.Name}") as InterfaceModel;

                    var property = @class.AddProperty(s.Name, serviceType)
                                   .MakeReadOnly();

                    constructorParameters.Add(new MethodParameter(property.Name.ToCamelCase(), serviceType));
                }

                // Generate constructor
                @class.AddConstructor()
                .WithParameters(constructorParameters.ToArray())
                .WithBody(builder =>
                {
                    builder.AssignPropertiesFromParameters();
                })
                .MakeProtected();
            }
        }
示例#22
0
        public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
        {
            if (type is Aggregate aggregate && model is ClassModel @class)
            {
                @class = @class.WithBaseType(SystemTypes.AggregateRoot(@class));

                foreach (var p in aggregate.Properties)
                {
                    @class.AddDomainProperty(p, registry);
                }

                if (aggregate.UniqueIdentifier != null && aggregate.UniqueIdentifier.Type.Resolve(registry) != SystemTypes.Guid)
                {
                    var parameter = new MethodParameter("id", aggregate.UniqueIdentifier.Type.Resolve(registry));

                    var method = @class.AddMethod("ToGuid")
                                 .WithReturnType(SystemTypes.Guid)
                                 .WithParameters(parameter);

                    var property = aggregate.UniqueIdentifier.Denormalized();
                    if (property.Type.Resolve(registry) == SystemTypes.Guid)
                    {
                        method.WithBody(builder =>
                        {
                            builder.Return(parameter.Property(aggregate.UniqueIdentifier.Type.Type.Properties.First().Name));
                        }).MakeProtected().MakeVirtual();
                    }

                    @class.AddMethod("FromGuid")
                    .WithReturnType(aggregate.UniqueIdentifier.Type.Resolve(registry))
                    .WithParameters(new MethodParameter("id", SystemTypes.Guid))
                    .WithBody(builder => { builder.ThrowNotImplemented(); })
                    .MakeProtected().MakeVirtual();
                }

                foreach (var domainEvent in aggregate.Module.GetTypes <DomainEvent>().Where(e => e.Aggregate == aggregate))
                {
                    if (registry.Resolve(Layer, domainEvent) is ClassModel domainEventClass)
                    {
                        var parameters = GenerateDomainEventParameters(registry, domainEvent, aggregate).ToList();

                        // Add method for publishing domain event
                        @class.AddMethod($"Publish{domainEvent.Name}")
                        .WithParameters(parameters.ToArray())
                        .MakeProtected()
                        .MakeVirtual()
                        .WithBody(builder =>
                        {
                            BuildDomainEventPublisher(registry, builder, aggregate, @class, domainEventClass, parameters);
                        });

                        // Add method for applying domain event
                        var @event = new MethodParameter("@event", domainEventClass);
                        @class.AddMethod(SystemTypes.DomainEventApplyMethodName)
                        .WithParameters(@event)
                        .MakeVirtual()
                        .WithBody(builder =>
                        {
                            BuildDomainEventApply(builder, domainEvent, @event);
                        });
                    }
                }

                foreach (var metaMethod in aggregate.Methods)
                {
                    var method = @class.AddMethod(metaMethod.Name)
                                 .WithParameters(metaMethod.Parameters.Select(p => new MethodParameter(p.Name, p.Type.Resolve(registry))).ToArray());

                    if (metaMethod.Return != null)
                    {
                        method = method.WithReturnType(metaMethod.Return.Type.Resolve(registry));
                    }
                }
            }
        }
示例#23
0
 public abstract void GenerateModule(Module module, NamespaceModel @namespace, ITypeModelRegistry registry);
示例#24
0
 public override void GenerateModule(Module module, NamespaceModel @namespace, ITypeModelRegistry registry)
 {
 }
示例#25
0
 public abstract void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry);
示例#26
0
        public override void GenerateModule(Module module, NamespaceModel @namespace, ITypeModelRegistry registry)
        {
            if (GetTypes(module).Any())
            {
                var @class = @namespace.AddClass($"{module.Name}DbContext");

                foreach (var aggregate in module.GetTypes <Aggregate>())
                {
                    @class.AddProperty($"{aggregate.Name}Set", SystemTypes.DbSet(registry.Resolve(Layer, aggregate)));
                }

                registry.Register(Layer, module, @class);
            }
        }
示例#27
0
 public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry)
 {
 }
示例#28
0
 private static MethodParameter GenerateMethodParameter(ITypeModelRegistry registry, MetaParameter p)
 {
     return(new MethodParameter(p.GetDomainName(), p.GetDomainType(registry)));
 }
示例#29
0
        public static void AddViewModelProperty(this ClassModel @class, Property property, ITypeModelRegistry registry)
        {
            TypeModel propertyType;

            if (property.Type.SystemType != null)
            {
                propertyType = SystemTypes.Parse(property.Type.SystemType);
            }
            else if (!(property.Type.Type is Enumeration))
            {
                var viewModel = registry.GetAllBaseTypes <ViewModel>("Application").SingleOrDefault(vm => vm.IsCompact && vm.Target == property.Type.Type);
                propertyType = registry.Resolve("Application", viewModel);
            }
            else
            {
                propertyType = property.Type.Resolve(registry);
            }

            if (property.IsCollection)
            {
                propertyType = SystemTypes.List(propertyType);
            }

            @class.AddProperty(property.Name, propertyType)
            .WithDescription(property.Description);
        }
示例#30
0
 public static void AddDomainProperty(this ClassModel @class, Property property, ITypeModelRegistry registry)
 {
     @class.AddProperty(property.GetDomainName(), property.GetDomainType(registry))
     .WithDescription(property.Description)
     .MakeReadOnly();
 }