镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

RegisterSingletonAttribute support export static object #247

Open

Description

@MikiraSora

In MEF there is a export example like this:

[Export]
 public static MenuBarDefinition MainMenuBar = new MenuBarDefinition();

Injectio does not support this operation, but we can implement it. Theoretically, by using the following code:

namespace Gemini.Modules.MainMenu
{
  public static class MenuDefinitions
  {
    [RegisterSingleton<MenuDefinition>]
    public static MenuDefinition MainMenuBar = new MenuBarDefinition();
  }
}

we can then generate

global::Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAdd(
                serviceCollection,
             global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Scoped<global::Gemini.Framework.Menus.MenuBarDefinition>(_=>Gemini.Modules.MainMenu.MenuDefinitions.MainMenuBar)
            );

Therefore, Injectio can extend the RegisterSingletonAttribute. This attribute can decorate fields and auto-properties. they must be public and static, and cannot be null.

Activity

  1. Cologler commented on Feb 21, 2026

    @Cologler

    It should also support properties with the internal modifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions