Jimmy Bogards crossing the generics divide

Search for a command to run...

No comments yet. Be the first to comment.
Phew, that was a lot. I'm always surprised how simple solutions contain so much detail and nuance when I try to explain them. I hope I conveyed the message that A-Frame simplifies code within a module or class by separating the infrastructure compone...

No architecture is complete without an easy way to test the functionality. My recommended strategy is to use two types of tests: unit and integration. As far as test setup goes, there is no clear winner for a test framework. xUnit.NET, NUnit and the ...

The examples in the previous posts seem really nice for simple scenarios. How do I approach more advanced use cases? The big scenarios are: I need multiple pieces of data from different sources I need to perform an infrastructure call in the middle...

I’ve shown how I write code using the A-Frame architecture without help. Yet I find a library or framework very convenient when using advanced techniques. Wolverine is at its core a messaging framework, but goes well beyond that. It has an in-memory ...

Now the expected structure is clear, let's take a look at the code. I will start with a minimal API implementation to demonstrate that there is no need for a framework to implement this architecture. I do know of a framework that makes A-Frame effort...

Jimmy Bogard wrote a blog quite recently about how to inject generic components without using the generic part. As I have struggled with this in the past, I thought I’d create a little implementation to check out how his article solves the problem.
So I created a GitHub repository named Crossing The Generics Divide. I did put it in a namespace KenBonny, not (only) because I did the copy pasting from Jimmy’s blog, but to show that this is not made by Jimmy. It’s just a tribute. I did do one thing different: Jimmy uses “validators”, I replaced that by “processor” as I wanted to return a result (which is just a bit of text to differentiate between the processors).
The most important lesson that I learned is that the composition has my preference, but that I cannot inject the general IPolicyProcessor (Jimmy’s IPolicyValidator) directly. I need to ask for the specific PolicyProcessor<> as I cannot pass the type of Policy to the factory method with basic dependency injection.
There is an example with the IPolicyProcessor that comes from a factory, but this required a bit of extra work in a console application. The IServiceProvider does not automatically get registered if I did it manually. To get this working, I had to set up a hosting environment (as described by the Microsoft docs). So if the normal execution is an asp.net project, this should work out of the box.