Skip to content

Document mixing real framework services with Moq AutoMock (#49) - #185

Merged
tillig merged 2 commits into
mainfrom
feature/moq-automock-framework-services
Jun 29, 2026
Merged

Document mixing real framework services with Moq AutoMock (#49)#185
tillig merged 2 commits into
mainfrom
feature/moq-automock-framework-services

Conversation

@tillig

@tillig tillig commented Jun 29, 2026

Copy link
Copy Markdown
Member

Companion to autofac/Autofac.Extras.Moq#61, addressing autofac/Autofac.Extras.Moq#49.

Adds a "Mixing Real Framework Services with Auto-Mocking" section to the Moq integration docs (docs/integration/moq.rst).

It explains:

  • AutoMock injects a mock for any unresolved service, including the elements of an otherwise-empty collection dependency (e.g. IEnumerable<ILoggerProvider>).
  • A loose mock element returns null for un-setup members, which can make a consuming framework throw — frequently a NullReferenceException deep inside the framework (the EF Core + logging case from the issue).
  • A note that the failure can appear intermittently (e.g. only in a certain test order) because frameworks like EF Core cache internal state that masks the problem.
  • The workaround: register the concrete services the framework consumes (e.g. a real ILoggerFactory), or keep real framework wiring out of the auto-mock container.

@tillig
tillig merged commit 2a20cf8 into main Jun 29, 2026
2 checks passed
@tillig
tillig deleted the feature/moq-automock-framework-services branch June 29, 2026 21:40
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