factory-function-composition

Compose clients and services using factory functions with dependency injection.

35|4|Updated Dec 18, 2024
One-click install
npx skills add https://github.com/wellcrafted-dev/wellcrafted --skill factory-function-composition-wellcrafted-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: factory-function-composition
Source: https://github.com/wellcrafted-dev/wellcrafted/tree/main/.claude/skills/factory-function-composition
Command: npx skills add https://github.com/wellcrafted-dev/wellcrafted --skill factory-function-composition-wellcrafted-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the complexity of managing dependencies and configurations when building clients and services, promoting a cleaner, more testable, and reusable codebase.

Core Features & Use Cases

  • Dependency Injection: Facilitates passing external clients and resources into functions.
  • Configuration Separation: Ensures client, service, and method-specific options remain distinct.
  • Testability: Simplifies unit testing by allowing easy injection of mock dependencies.
  • Use Case: Refactoring a large service that currently creates its own database client internally, making it hard to test or reuse with different database configurations.

Quick Start

Use the factory-function-composition skill to create a new service that depends on a database client and a cache client.

Frequently Asked Questions about factory-function-composition

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use factory functions for dependency injection in TypeScript?

Use factory functions for dependency injection by passing external clients into a function, allowing you to compose services with proper separation of concerns and inject mock dependencies for testing.

What is the best way to separate client configuration from service logic?

Separating client configuration from service logic is best achieved using factory function patterns, which ensure client, service, and method-specific options remain distinct and manageable.

How do I refactor a service that creates its own database client internally?

Refactor a service creating its own database client by applying factory function composition to inject the client as a dependency, making the service testable and reusable with different configurations.

Can I wrap external resources with domain-specific methods using factory functions?

Yes, you can wrap external resources with domain-specific methods using factory functions, which provides a universal signature for dependency injection and cleanly manages configuration.

Why does mixing client and service options make my code hard to test?

Mixing client and service options makes code hard to test because dependencies are tightly coupled and hidden internally, preventing the injection of mock clients needed for isolated unit tests.

When should I not use factory function composition for service creation?

Avoid factory function composition for service creation when dealing with simple, stateless utilities that have no external dependencies or configuration requirements to manage.