public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry) { if (type is InputModel inputModel && model is ClassModel @class) { GenerateInputModel(registry, inputModel, @class); } }
public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry) { if (type is ViewModel viewModel && model is ClassModel @class) { GenerateViewModel(registry, viewModel, @class); } }
public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry) { if (type is Command command && model is ClassModel @class) { @class.WithBaseType(SystemTypes.Command()); } }
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(); }); } }
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())); } }
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); }
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); }
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); } } }
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); } } }
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))); } }
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)); } }
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); }
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); } } }
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); } } }
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); } } }
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(); }); } }
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(); } }); } }
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); }
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(); } }
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)); } } } }
public abstract void GenerateModule(Module module, NamespaceModel @namespace, ITypeModelRegistry registry);
public override void GenerateModule(Module module, NamespaceModel @namespace, ITypeModelRegistry registry) { }
public abstract void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry);
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); } }
public override void GenerateType(BaseType type, TypeModel model, ITypeModelRegistry registry) { }
private static MethodParameter GenerateMethodParameter(ITypeModelRegistry registry, MetaParameter p) { return(new MethodParameter(p.GetDomainName(), p.GetDomainType(registry))); }
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); }
public static void AddDomainProperty(this ClassModel @class, Property property, ITypeModelRegistry registry) { @class.AddProperty(property.GetDomainName(), property.GetDomainType(registry)) .WithDescription(property.Description) .MakeReadOnly(); }