#1707 Support multiple parameters and [Inject] in ObjectFactory data portal#4868
Open
rockfordlhotka wants to merge 2 commits into
Open
#1707 Support multiple parameters and [Inject] in ObjectFactory data portal#4868rockfordlhotka wants to merge 2 commits into
rockfordlhotka wants to merge 2 commits into
Conversation
…portal Route FactoryDataPortal method invocation through the DI-aware ServiceProviderMethodCaller so factory methods can accept multiple criteria parameters and method-level [Inject] dependencies, matching the encapsulated model. Falls back to the legacy single-criteria path when no DI-aware match is found, preserving Invoke/InvokeComplete/ InvokeError hooks. Include the resolved factory type in the ServiceProviderMethodCaller method-cache key so swapped factory types for the same business type do not collide in the process-wide cache. Convert factory Task<T> returns via TaskConversionHelper since Task<T> is invariant and cannot be cast to Task<object>. Constructor injection already worked and is now test-covered; operation attributes on factory methods remain out of scope. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates CSLA’s ObjectFactory data portal invocation to support the same multi-criteria parameter passing and method-level [Inject] dependency injection that already exist for the encapsulated model, while preserving factory lifecycle hook behavior and providing legacy fallback behavior when a DI-aware match isn’t available.
Changes:
- Route
FactoryDataPortalfactory method invocation throughServiceProviderMethodCaller(with legacy fallback) to support multiple criteria parameters and method-level[Inject]. - Extend
ServiceProviderMethodCaller’s method-cache key to include the resolved factory type to avoid cross-factory delegate reuse. - Add
Task<T>return handling for factory methods via a cached conversion helper, plus new test fixtures and coverage for multi-parameter +[Inject]scenarios.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Source/Csla/Server/FactoryDataPortal.cs | Switches factory invocation to DI-aware method calling with multi-criteria + [Inject] support and legacy fallbacks. |
| Source/Csla/Reflection/ServiceProviderMethodCaller.cs | Includes resolved factory type in cache key; updates Task<T> handling to convert to Task<object>. |
| Source/Csla/Reflection/ServiceProviderMethodInfo.cs | Caches a conversion MethodInfo for Task<T>-to-Task<object> invocation support. |
| Source/tests/Csla.test/ObjectFactory/ObjectFactoryTests.cs | Adds coverage for multi-parameter criteria, method-level [Inject], overload resolution, ctor injection, and command Execute with injection. |
| Source/tests/Csla.test/ObjectFactory/MultiParamInjectFactories.cs | New factory fixtures covering multi-criteria and injected parameters/ctor injection. |
| Source/tests/Csla.test/ObjectFactory/InjectCommandObject.cs | New command object + factory fixture validating Execute criteria + [Inject] in ObjectFactory path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
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.
Fixes #1707.
Brings the factory (ObjectFactory) data access model up to parity with the encapsulated model for parameter passing and dependency injection.
What changed
FactoryDataPortalnow invokes factory methods through the DI-awareServiceProviderMethodCallerinstead of the legacy single-criteriaMethodCaller. This enables:[Inject]parameters resolved from the service provider.It falls back to the legacy single-criteria path when no DI-aware match is found, and preserves the existing
Invoke/InvokeComplete/InvokeErrorlifecycle hooks and event-arg semantics (including the command-object Update→Execute case).ServiceProviderMethodCaller— the process-wide method cache was keyed only on the business object type. Since the factory path now uses this cache, the resolved factory type is included in the cache key. This is a no-op in production (one factory per business type) and for the encapsulated path (no factory attribute), but prevents a delegate compiled for one factory from being invoked against another.ServiceProviderMethodInfo— factory methods may returnTask<T>(the business object). BecauseTask<T>is invariant it cannot be cast toTask<object>, so a cachedConvertToTaskObjectMethod(via the existingTaskConversionHelper) is now used, mirroringMethodCaller/DynamicMethodHandle.Scope decisions
ObjectFactoryLoader.GetFactory→CreateInstanceDI); it is now covered by a test.[Create]/[Fetch]etc.) on factory methods are intentionally out of scope — the ObjectFactory method-name convention remains the only mechanism.Tests
New fixtures (
MultiParamInjectFactories.cs,InjectCommandObject.cs) and tests inObjectFactoryTests.cscover: multiple parameters, method-level[Inject], multi-param +[Inject]combined, overload disambiguation, constructor injection, and command-object Execute with injection.Full CI-parity suite (
TestCategory!=SkipOnCIServer) passes with 0 failures across all assemblies.🤖 Generated with Claude Code