agentleFS
adrianosantostreinaadrianosantostreina/delphi-dev/skills/delphi-spring4d/SKILL.md

delphi-spring4d

Skill87 starsChanged 5 months agoMITView on GitHub

Especialista em Spring4D (Dependency Injection, Collections e padrões) em Delphi. Auto-ativa quando detectar: Spring4D, Spring.Container, GlobalContainer, TContainer, RegisterType, IList<T>, IDictionary<T>, IEnumerable<T>, TCollections, injeção de dependência, DI container, IoC, "registrar serviço", "resolver dependência".

The file

Files
SKILL.md

Delphi Spring4D

Idioma de saída

Detecte o idioma da primeira mensagem. Padrão: pt-BR. Respeite overrides explícitos.

Quando usar Spring4D

  • DI Container — quando o grafo de dependências cresce e o constructor injection manual fica trabalhoso de montar (ver rules/architecture.md para a base de DI).
  • Collections — IList<T>, IDictionary<TK,TV>, IEnumerable<T> com semântica de interface (ARC) em vez de TObjectList<T> manual.

DI Container — registro e resolução

uses
  Spring.Container;

// Registro (na inicialização da aplicação)
GlobalContainer.RegisterType<IClienteRepository, TClienteFDRepository>;
GlobalContainer.RegisterType<IClienteService, TClienteService>;
GlobalContainer.Build;

// Resolução
var LService: IClienteService;
LService := GlobalContainer.Resolve<IClienteService>;

O container resolve a cadeia: ao pedir IClienteService, injeta automaticamente o IClienteRepository no construtor de TClienteService.

Tempo de vida (lifetime)

GlobalContainer.RegisterType<IClienteService, TClienteService>
  .AsSingleton;          // uma instância para toda a aplicação
// .AsTransient (padrão)  // nova instância a cada Resolve
// .PerResolve            // uma instância por grafo de resolução

Collections

uses
  Spring.Collections;

var
  LClientes: IList<TCliente>;
begin
  LClientes := TCollections.CreateObjectList<TCliente>(True); // owns objects
  LClientes.Add(TCliente.Create);
  // Sem try/finally manual — ARC libera a lista e seus objetos
end;

Regras

  • Registrar interfaces → implementações, nunca classes concretas diretamente
  • Preferir AsSingleton para services/repositories sem estado mutável
  • IList<T> / IDictionary<T> (interface) em vez de TList<T> quando quer ARC
  • O container não substitui o rules/architecture.md — é a ferramenta que automatiza o constructor injection que aquele documento exige

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.