Skip to content

feat(abstractions): add ILambdaMiddlewareFactory interface #259

Description

@j-d-ha

Description

Add an ILambdaMiddlewareFactory interface to support custom middleware creation logic.

Motivation

Currently, middleware can be registered using UseMiddleware<T>(), but there's no built-in way to customize how middleware instances are created. A factory interface would enable:

  • Custom middleware initialization logic
  • Advanced dependency injection scenarios
  • Middleware pooling or reuse strategies
  • Complex constructor parameter resolution

Proposed Interface

public interface ILambdaMiddlewareFactory
{
    ILambdaMiddleware Create(Type middlewareType);
}

Or with generics:

public interface ILambdaMiddlewareFactory
{
    TMiddleware Create<TMiddleware>() where TMiddleware : ILambdaMiddleware;
}

Implementation Considerations

  • Should integrate with the existing middleware pipeline
  • Should work seamlessly with UseMiddleware<T>()
  • Consider whether to support both generic and non-generic versions
  • Determine whether factory should be registered per middleware type or globally
  • Consider lifetime management (transient, scoped, singleton)

Acceptance Criteria

  • ILambdaMiddlewareFactory interface is added to MinimalLambda.Abstractions
  • Factory can be registered with the host builder
  • Factory is used when creating middleware instances
  • Unit tests cover factory integration
  • Example demonstrates custom factory usage
  • Documentation explains when and how to use the factory

Related

This relates to the existing class-based middleware support introduced in #257.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions