Skip to content

Editor hint: service registered as concrete type but implements an interface#16

Open
PaulNonatomic wants to merge 1 commit into
mainfrom
feat/editor-interface-hint
Open

Editor hint: service registered as concrete type but implements an interface#16
PaulNonatomic wants to merge 1 commit into
mainfrom
feat/editor-interface-hint

Conversation

@PaulNonatomic
Copy link
Copy Markdown
Owner

Summary

Adds a runtime/editor counterpart to analyzer rule SK006. In the ServiceKit window, a service that is registered under its concrete type but implements a user-defined interface — one that is not itself registered in the locator — now shows a small amber i badge. The tooltip suggests registering it as the interface with [Service(typeof(IFoo))].

This surfaces, at a glance, the common traps:

  • A forgotten [Service(typeof(IFoo))] (service registered as its concrete type, consumers expect the interface).
  • [Service] placed on an abstract base class, where it has no effect because the attribute is declared Inherited = false — exactly the V1→V2 migration trap.

Behaviour / false-positive guards

  • Interface-keyed registrations never trigger it (serviceType.IsInterface → no badge).
  • If the interface is registered elsewhere in the same locator (intentional dual registration), it's excluded — no badge.
  • Only user-defined interfaces are considered; System.*, UnityEngine.*, UnityEditor.*, Unity.*, Cysharp.*, Mono.*, Microsoft.* are filtered out.
  • Only the most-derived interfaces are listed (a base that another listed interface extends is dropped).

Files

  • Editor/ServiceKitWindow/ServiceItem.cs — hint computation + amber badge (inline-styled, class hook service-interface-hint for future theming).
  • CHANGELOG.md — Unreleased entry.

Validation

Self-reviewed; not yet compiled in Unity (no Unity available in this environment). Needs an editor compile + a quick visual check that the badge renders and the tooltip reads correctly. Happy to run an EditMode batchmode compile if you close Unity, as before.

…plements an interface

The ServiceKit window now shows an amber 'i' badge on a service registered under its concrete type when that type implements a user-defined interface that is not itself registered in the locator. The tooltip suggests [Service(typeof(IFoo))]. This surfaces the common trap of a forgotten attribute, or one placed on an abstract base (where it has no effect because [Service] is not inherited) -- the runtime counterpart to analyzer rule SK006.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant