Best way to override Delegate creation while keeping all other customizations
See original GitHub issueWe often use factory methods (Func<T>) in classes. This works well in conjunction with AutoFixture. The only problem I have is that the generated code always returns the same value.
Let´s take a sample class:
public class Sample
{
private readonly Func<IFoo> _createFoo;
public Sample(Func<IFoo> createFoo)
{
_createFoo = createFoo;
}
}
So if I would have to write the code AutoFixture does automatically it would look like this:
var fixture = CreateFixture();
var foo = fixture.Create<IFoo>();
var sample = new Sample(() => foo);
I am of course simplifying what AutoFixture does, but the result is that I will always get the same instance whenever I call the factory method. Can someone please direct me into customizing this behavior so that the result is like this:
var fixture = CreateFixture();
var sample = new Sample(() => fixture.Create<IFoo>());
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Make a delegate method in custom class overridable in Swift
This is a subclass, it needs override if you want the function to have a different body. class MySubClass : Myclass { override...
Read more >Solved: Overwriting Created On & Created By?
Solved: I am importing data to an existing entity in CDS using the Get data from Excel button. My data contains information about...
Read more >Implementing a Custom Delegate | TensorFlow Lite
The preferred method to add a delegate is using SimpleDelegate API. To create a new delegate, you need to implement 2 interfaces and...
Read more >Events & Delegates in Unity
Learn how to connect scripts & objects using delegates, actions & Unity Events in my in-depth beginner's guide.
Read more >Delegated properties
A property can delegate its getter and setter to another property. Such delegation is available for both top-level and class properties (member ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should we tag this issue so that if a new major version was to come, we could take the chance to introduce this breaking change?
Yes I would love to see this changed in the future, but as said, there might be someone out there relying on this behavior.