Skip to content

#1707 Support multiple parameters and [Inject] in ObjectFactory data portal#4868

Open
rockfordlhotka wants to merge 2 commits into
mainfrom
feature/objectfactory-multiparam-inject
Open

#1707 Support multiple parameters and [Inject] in ObjectFactory data portal#4868
rockfordlhotka wants to merge 2 commits into
mainfrom
feature/objectfactory-multiparam-inject

Conversation

@rockfordlhotka

@rockfordlhotka rockfordlhotka commented Jun 16, 2026

Copy link
Copy Markdown
Member

Fixes #1707.

Brings the factory (ObjectFactory) data access model up to parity with the encapsulated model for parameter passing and dependency injection.

What changed

  • FactoryDataPortal now invokes factory methods through the DI-aware ServiceProviderMethodCaller instead of the legacy single-criteria MethodCaller. This enables:

    • Multiple criteria parameters on factory Create/Fetch/Update/Delete/Execute methods.
    • Method-level [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/InvokeError lifecycle 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 return Task<T> (the business object). Because Task<T> is invariant it cannot be cast to Task<object>, so a cached ConvertToTaskObjectMethod (via the existing TaskConversionHelper) is now used, mirroring MethodCaller/DynamicMethodHandle.

Scope decisions

  • Constructor injection of the factory already worked (ObjectFactoryLoader.GetFactoryCreateInstanceDI); it is now covered by a test.
  • Operation attributes ([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 in ObjectFactoryTests.cs cover: 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

…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 FactoryDataPortal factory method invocation through ServiceProviderMethodCaller (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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement multi-parameter and inject features for ObjectFactory

2 participants