Skip to content

XpoDatabaseOptions.SetAsXpoDefault, and a strict ParseEnum overload - #24

Merged
donwibier merged 3 commits into
masterfrom
feat/xpodefault-option-strict-parseenum
Nov 5, 2026
Merged

donwibier merged 3 commits into
masterfrom
feat/xpodefault-option-strict-parseenum

Conversation

@donwibier

Copy link
Copy Markdown
Owner

Summary

This PR resolves the two behaviours that #23 left pinned as skipped "BY DESIGN?" tests. No tests are skipped any more.

XpoDatabase and XpoDefault.DataLayer (DX.Data.Xpo 26.1.3.41)

XpoDatabase used to set the process-wide XpoDefault.DataLayer as a side effect. That had several problems:

  • It depended on the schema option. It only happened when UpdateSchema was DatabaseAndSchema, which is typical in development and rare in production. Code relying on it worked in dev and broke in production.
  • The last database created won. With several databases, the global pointed at whichever was created last.
  • It wasn't the layer XpoDatabase hands out. It was a separate ThreadSafeDataLayer over the same store.
  • It contradicted the code around it. XpoDatabase sets XpoDefault.Session = null to prevent accidental use of XPO's defaults.

This PR removes the implicit assignment and adds XpoDatabaseOptions.SetAsXpoDefault (default false). When set, XpoDefault.DataLayer becomes that database's own data layer, whatever the schema option. Nothing in this repo relies on the global.

Behaviour change: code that creates sessions without a data layer (new UnitOfWork(), new Session(), an XPCollection without a session) must now set SetAsXpoDefault = true. This is documented in the root README, the DX.Data.Xpo README and the release notes.

Tests:

  • The previously skipped Ctor_DoesNotReplaceXpoDefaultDataLayer now runs and passes.
  • New tests cover:
    • the opt-in, including a session created without a data layer;
    • the opt-in on an existing database opened with SchemaAlreadyExists;
    • with several databases, only the one that opts in becomes the default.

ParseEnum (DX.Utils 26.1.3.42)

The existing overloads are unchanged. They follow Enum.TryParse, so "99" still gives (TEnum)99, as the docs promise; only conversion errors return the default.

This PR adds an opt-in overload, ParseEnum(value, defaultValue, definedOnly, ignoreCase = false):

  • With definedOnly, a value must be one of the enum's members.
  • For a [Flags] enum, any combination of its flags is accepted.
  • It works for signed and unsigned underlying types, including ulong.

IsDefinedEnumValue(value) is also exposed. The skipped test is replaced by one pinning today's behaviour, plus tests for strict mode ([Flags], ignoreCase, and ulong/sbyte underlying types).

Versions

Package Version
DX.Data.Xpo 26.1.3.41
DX.Utils 26.1.3.42

Each is one above what's on NuGet now. The commits deliberately avoid a "BREAKING CHANGE" footer, so the GitHub release goes to v1.4.0 (from the feat commits) rather than v2.0.0.

Testing

Tests run locally on net10.0 for every test project, and on net8.0 for DX.Utils.Tests and DX.Data.Xpo.Tests. Nothing is skipped and nothing fails.

Tests Pass
DX.Utils.Tests 332
DX.Data.Xpo.Tests 169
DX.Data.Xpo.Identity.Tests 250
DX.Data.EF.Tests 109

🤖 Generated with Claude Code

donwibier and others added 3 commits November 4, 2026 21:22
….DataLayer

XpoDatabase set the process-wide XpoDefault.DataLayer as a side effect, but only
when UpdateSchema was DatabaseAndSchema (typical in development, rare in
production) and then to whichever database was created last, as a separate
data layer over the same store. That contradicted XpoDatabase setting
XpoDefault.Session to null to prevent accidental use of the defaults.

The new SetAsXpoDefault option (default false) sets XpoDefault.DataLayer to the
database's own data layer, whatever the schema option.

Behaviour change (documented in the READMEs and release notes): code that
creates sessions without a data layer (new UnitOfWork(), new Session(),
XPCollection without a session) must set SetAsXpoDefault = true on the
database it should use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ParseEnum(value, defaultValue, definedOnly, ignoreCase = false): with
definedOnly, a value must be a member of the enum or, for a [Flags] enum, a
combination of its flags; anything else returns the default. The existing
overloads keep following Enum.TryParse. Also IsDefinedEnumValue(value), and the
root README section for this follow-up release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s instead of failing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@donwibier
donwibier merged commit 854318d into master Nov 5, 2026
2 checks passed
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.

1 participant