-
Notifications
You must be signed in to change notification settings - Fork 0
Add Middleware Support to PySpring Framework #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Introduced ContainerManager, DependencyInjector, ComponentManager, BeanManager, and PropertiesManager to streamline the management of components, beans, and properties. - Enhanced error handling and logging for dependency injection failures. - Updated tests to reflect changes in the application context structure and ensure proper registration and retrieval of components, beans, and properties. - Improved documentation for classes and methods to clarify their responsibilities and usage.
- Updated the _validate_bean_view method to include a type hint for the view parameter, specifying it as BeanView. - This change improves code clarity and helps with static type checking.
- Introduced Middleware and MiddlewareRegistry classes to manage middleware application in the FastAPI application. - Refactored PySpringApplication to initialize middlewares during application startup. - Updated RestController documentation to clarify middleware registration process. - Bumped version to 0.0.20 to reflect the addition of new features.
…iddleware and MiddlewareRegistry - Added pytest-asyncio to the development dependencies for async testing support. - Created a new test suite for Middleware and MiddlewareRegistry, covering various scenarios including abstract class enforcement, middleware execution order, and early returns. - Ensured that middleware functionality is thoroughly validated through integration tests, enhancing overall test coverage.
…he count and names of found subclasses
- Included Middleware in the __all__ list to ensure it is accessible for import. - Updated import statements to reflect the addition of Middleware, enhancing module functionality.
- Updated the subclass validation logic to use a dictionary for tracking unique subclass names, ensuring only one subclass is allowed. - Enhanced the error message to include the count and names of found subclasses for better clarity.
- Added a method to ApplicationContext for injecting dependencies into external objects, improving flexibility in middleware initialization. - Updated PySpringApplication to log the injection of dependencies and refactor middleware application logic for better clarity and structure.
- Added logging for the injection of dependencies into middleware classes during application initialization. - Improved clarity in middleware setup by explicitly logging each middleware class being processed.
- Expanded the docstring for MiddlewareRegistry to clarify the automatic middleware registration and execution order. - Explained the stacking behavior of middlewares during request and response paths, providing an example for better understanding.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Middleware Support to PySpring Framework
Overview
This PR introduces comprehensive middleware support to the PySpring framework, allowing developers to easily add custom request/response processing logic to their FastAPI applications. The implementation provides a clean, Spring-inspired middleware architecture with dependency injection support.
🚀 New Features
1. Middleware Base Class (
Middleware
)py_spring_core/core/entities/middlewares/middleware.py
BaseHTTPMiddleware
process_request
method for custom logic2. Middleware Registry (
MiddlewareRegistry
)py_spring_core/core/entities/middlewares/middleware_registry.py
SingleInheritanceRequired
3. Single Inheritance Interface (
SingleInheritanceRequired
)py_spring_core/core/interfaces/single_inheritance_required.py
🔧 Core Framework Updates
PySpring Application Updates
py_spring_core/core/application/py_spring_application.py
__init_middlewares()
method for automatic middleware initializationRestController Simplification
py_spring_core/core/entities/controllers/rest_controller.py
register_middlewares()
method (no longer needed)📦 Package Updates
Version Bump
0.0.18
→0.0.19
Dependencies
pytest-asyncio>=1.1.0
for async test supportPublic API Exports
Middleware
andMiddlewareRegistry
to__all__
list🧪 Comprehensive Test Suite
Test Coverage
tests/test_middleware.py
(389 lines)Test Categories
💡 Usage Example
🔄 Breaking Changes
For Existing Users
register_middlewares()
method fromRestController
MiddlewareRegistry
subclass🎯 Benefits
📋 Checklist
🔍 Testing
Run the test suite to verify all functionality:
All tests should pass, including async middleware execution and integration tests.
Note: This PR maintains backward compatibility while introducing powerful new middleware capabilities that align with Spring Framework patterns.