How to use the instantiator to create a named domain object?


(Dimitar Dimitrov) #1

I am trying to have a domain object container and use the instantiator to create the domain objects. The problem is that I get a “no such constructor” message.

Here is a code snippet (let me know if I should come with a full repro case).

@CompileStatic
class ModelleratorExtension {
    final Property<String> toolVersion
    final Property<String> ontologyType
    final ListProperty<String> modelAspects
    final NamedDomainObjectContainer<GeneratedArtifactConfig> generatedArtifacts

    ModelleratorExtension(Project project) {
        this.toolVersion = project.objects.property(String)
        this.ontologyType = project.objects.property(String)
        this.modelAspects = project.objects.listProperty(String)
        this.generatedArtifacts = project.container(GeneratedArtifactConfig) { name ->
            def ga = project.objects.newInstance(GeneratedArtifactConfig, name)
            ga.ontologyType.set(ontologyType)
            ga.modelAspectTypes.set(modelAspects)
            return ga
        }
    }

    void generatedArtifacts(Closure config) {
        generatedArtifacts.configure(config)
    }
}

@CompileStatic
class GeneratedArtifactConfig {
    final String name
    final Property<String> ontologyType
    final ListProperty<String> modelAspectTypes
    final RegularFileProperty template
    final Property<TextResource> entities
    final ListProperty<GeneratedArtifactConfig> dependsOn

    @Inject
    GeneratedArtifactConfig(String name, ObjectFactory obf, ProjectLayout prl) {
        this.name = name
        ontologyType = obf.property(String)
        modelAspectTypes = obf.listProperty(String)
        template = prl.fileProperty()
        entities = obf.property(TextResource)
        dependsOn = obf.listProperty(GeneratedArtifactConfig)

    }
}

(Stefan Oehme) #2

Dependency injection is not yet supported by the object factory, though it would be really useful. Would you mind opening an issue for that?