Poor Man's Dependency Injection using Generics(jeremyjarrell.com)

submitted by jeremyjarrelljeremyjarrell(2685) 4 years, 4 months ago

Here's a quick way to incorporate dependency injection into your code using generics. This technique can be invaluable for testing.

2 comments |category: |Views: 150

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by .NetKicks.NetKicks(1304) 4 years, 4 months ago 0

I don't get it. Why should one want the lower layers of the application to create the instances? IMO this makes testing with mocking frameworks more difficult, because you can't inject a already initialised mockObject. Instead you tell the class under test to create a new instance of a mocked class you which have to be coded first. Does this approach take away the chance of using a mocking framework like NMock or Rhino.Mocks?

Reply

information Login or create an account to comment on this story