Skip to content

feat: Allow @ServiceProvider without specifying the contract #6

@LMLiam

Description

@LMLiam

Summary

The @ServiceProvider annotation should be expanded to allow annotation without needing to specify the contract.

Why is this needed?

Simpler syntax allows developers to come up to speed with the library quicker, and allows for faster development.

Proposed solution

Proposed syntax:

@ServiceContract
interface SomeContract {
  fun doSomething()
}

@ServiceProvider
class DefaultSomeContract : SomeContract {
  override fun doSomething() = Unit
}

The class(es) can be deterministically found via exploring the interfaces that parent the implementation and checking if they have @ServiceContract.

The annotation should still allow for manual specification of contracts to ensure conflicts do not occur:

@ServiceContract
interface SomeContractA {
  fun doSomething(): String
}

@ServiceContract
interface SomeContractB {
  fun doSomethingElse(): String
}

@ServiceProvider(SomeContractB::class)
class DefaultSomething : 
  SomeContractA, // We do not want to generate a service for this contract for this implementation
  SomeContractB {
  override fun doSomething(): String {
    return "Hello"
  }

  override fun doSomethingElse(): String {
    return doSomething() + " World!"
  }
}

@ServiceProvider
class AnotherSomething : SomeContractA {
  override fun doSomething(): String {
    return "Hello World"
  }
}

Checklist

  • I have searched existing issues to avoid duplicates

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions