Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Integration test for IoC registrations?

Integration test for IoC registrations?

Scheduled Pinned Locked Moved Design and Architecture
dockertestinghelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlexZieg71
    wrote on last edited by
    #1

    Hi, for our project we use Windsor Castle to do IoC. This means that we also let the IoC container resolve the needed constructor arguments. But for some cases (wrappers, view models, etc.) we also need to pass some ctor arguments which are only known at runtime and from my opinion are needed to create a valid object. For this we use generic factories like:

    interface IMyWrapperFactory
    {
    IMyWrapper CreateWrapper(string key);
    }

    For this to work I have IoC registered that factory as well as IMyWrapper, where the implementation of IMyWrapper only has one ctor overload with the string argument. Problem: we also have created an integration test which instantiates all registered components to ensure that everything can be resolved. But this fails for obvious reasons with IMyWrapper, as the string argument is not registered! I would be very happy if you could tell me what you think about it. 1. Is there a way to let certain components exclusively be instantiated by generic factories so the test could differ and it would not be possible to acquire an instance directly without using the needed string argument? 2. Am I wrong and it is generally bad practice to provide runtime parameters to constructors? 3. If not, would you limit your freedom of doing so just to make the integration test check 100% well? Best regards Alex

    S 1 Reply Last reply
    0
    • A AlexZieg71

      Hi, for our project we use Windsor Castle to do IoC. This means that we also let the IoC container resolve the needed constructor arguments. But for some cases (wrappers, view models, etc.) we also need to pass some ctor arguments which are only known at runtime and from my opinion are needed to create a valid object. For this we use generic factories like:

      interface IMyWrapperFactory
      {
      IMyWrapper CreateWrapper(string key);
      }

      For this to work I have IoC registered that factory as well as IMyWrapper, where the implementation of IMyWrapper only has one ctor overload with the string argument. Problem: we also have created an integration test which instantiates all registered components to ensure that everything can be resolved. But this fails for obvious reasons with IMyWrapper, as the string argument is not registered! I would be very happy if you could tell me what you think about it. 1. Is there a way to let certain components exclusively be instantiated by generic factories so the test could differ and it would not be possible to acquire an instance directly without using the needed string argument? 2. Am I wrong and it is generally bad practice to provide runtime parameters to constructors? 3. If not, would you limit your freedom of doing so just to make the integration test check 100% well? Best regards Alex

      S Offline
      S Offline
      senguptaamlan
      wrote on last edited by
      #2

      you can use MOQ for mocking and IOC for running the test cases.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups