Autofac.Extras.FakeItEasy
8.0.0
Prefix Reserved
dotnet add package Autofac.Extras.FakeItEasy --version 8.0.0
NuGet\Install-Package Autofac.Extras.FakeItEasy -Version 8.0.0
<PackageReference Include="Autofac.Extras.FakeItEasy" Version="8.0.0" />
<PackageVersion Include="Autofac.Extras.FakeItEasy" Version="8.0.0" />
<PackageReference Include="Autofac.Extras.FakeItEasy" />
paket add Autofac.Extras.FakeItEasy --version 8.0.0
#r "nuget: Autofac.Extras.FakeItEasy, 8.0.0"
#:package Autofac.Extras.FakeItEasy@8.0.0
#addin nuget:?package=Autofac.Extras.FakeItEasy&version=8.0.0
#tool nuget:?package=Autofac.Extras.FakeItEasy&version=8.0.0
Autofac.Extras.FakeItEasy
FakeItEasy auto mocking integration for Autofac.
Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.
Quick Start
The primary entry point for this integration is the Autofac.Extras.FakeItEasy.AutoFake class. Once you create an AutoFake, you can Resolve the class under test and Autofac will automatically fill its constructor dependencies with FakeItEasy fakes. You then configure and assert on those fakes the way you normally would with FakeItEasy.
[Fact]
public void DependenciesAreAutomaticallyFaked()
{
using (var fake = new AutoFake())
{
// Configure the fake dependency that will be injected.
A.CallTo(() => fake.Resolve<IDependency>().GetValue()).Returns("expected value");
// Resolve the system under test; its IDependency is the fake configured above.
var sut = fake.Resolve<SystemUnderTest>();
// Act and assert as usual.
Assert.Equal("expected value", sut.DoWork());
A.CallTo(() => fake.Resolve<IDependency>().GetValue()).MustHaveHappened();
}
}
To inject a specific instance or implementation instead of an automatic fake, register it through the configureAction constructor argument:
var dependency = new Dependency();
using (var fake = new AutoFake(configureAction: cfg => cfg.RegisterInstance(dependency).As<IDependency>()))
{
// SystemUnderTest receives your dependency instance.
var sut = fake.Resolve<SystemUnderTest>();
}
See the documentation for more usage details and options.
Migrating from 7.0.0
Version 8.0.0 removed the AutoFake.Provide<TService>(instance) and AutoFake.Provide<TService, TImplementation>() methods. Each Provide call started a new lifetime scope, which meant a fake resolved before the call was a different instance than the one injected afterward - so configuration applied to the earlier fake silently had no effect.
Register specific dependencies through the configureAction constructor argument instead. Everything is registered into a single scope before the container is built, so the instances you configure are the instances that get injected.
// Before (7.0.0)
using (var fake = new AutoFake())
{
var dependency = A.Fake<IDependency>();
fake.Provide(dependency);
var sut = fake.Resolve<SystemUnderTest>();
}
// After (8.0.0)
var dependency = A.Fake<IDependency>();
using (var fake = new AutoFake(configureAction: cfg => cfg.RegisterInstance(dependency).As<IDependency>()))
{
var sut = fake.Resolve<SystemUnderTest>();
}
For implementation registrations, register the type in configureAction and move any Autofac parameters onto the registration with WithParameter:
// Before (7.0.0): fake.Provide<IDependency, Dependency>();
// After (8.0.0):
using (var fake = new AutoFake(configureAction: cfg => cfg.RegisterType<Dependency>().As<IDependency>()))
{
var sut = fake.Resolve<SystemUnderTest>();
}
Version 8.0.0 also removed the builder constructor parameter (the one that let you pass your own ContainerBuilder). It was redundant with configureAction, so move any registrations from your own builder into the configureAction callback.
See the Migrating from 7.0.0 documentation for the full details.
Get Help
Need help with Autofac? We have a documentation site as well as API documentation. We're ready to answer your questions on Stack Overflow or check out the discussion forum.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Autofac (>= 9.3.0)
- FakeItEasy (>= 9.0.1)
-
net8.0
- Autofac (>= 9.3.0)
- FakeItEasy (>= 9.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Autofac.Extras.FakeItEasy:
| Package | Downloads |
|---|---|
|
DynamicSpecs.AutoFacItEasy
TypeRegistry for DynamicSpecs, based on AutoFac and FakeItEasy |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on Autofac.Extras.FakeItEasy:
| Repository | Stars |
|---|---|
|
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
|
|
|
Azure/Bridge-To-Kubernetes
Bridge To Kubernetes (B2K) is development tool to debug microservices, pods which redirects traffic to your local development machine and vice versa.
|
|
|
pkuehnel/TeslaSolarCharger
A software to let your Tesla charge with solar energy ☀
|
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.0 | 623 | 6/29/2026 |
| 7.0.0 | 833,550 | 9/29/2020 |
| 6.0.0 | 158,087 | 1/31/2020 |
| 5.0.1 | 369,983 | 6/4/2018 |
| 5.0.0 | 114,655 | 4/18/2017 |
| 4.0.0 | 86,724 | 6/30/2016 |
| 4.0.0-beta-230 | 2,139 | 3/11/2016 |
| 3.0.3 | 52,927 | 3/18/2015 |
| 3.0.2 | 24,066 | 3/27/2014 |
| 3.0.1 | 2,510 | 3/8/2014 |
| 3.0.0 | 5,171 | 1/7/2014 |
| 3.0.0-beta | 2,900 | 5/6/2013 |
Release notes are at https://github.com/autofac/Autofac.Extras.FakeItEasy/releases