Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3318834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:45:12+00:00 2026-05-17T22:45:12+00:00

We are using StructureMap as our Dependency Injection (DI) framework while we are creating

  • 0

We are using StructureMap as our Dependency Injection (DI) framework while we are creating a layered library. Our goals are to:

  • Make it easy for us to Unit Test classes (and using mock classes instead of the real dependencies) while we develop and maintain the library.
  • Make it easy for the library user to:
    • Customize the library behavior by implementing an interface them selfs and configuring the library to use their implementation instead of our own.
    • Unit Test their implemented classes (it’s the same goal we have internally, but we want it to be fulfilled for the library user as well).

By layered library, we mean that we are building two DLL`s:

  1. The core library. It should be usable from any .NET application, be it a Console application or an MVC one.
  2. A WebForms library. It includes the core library but also provides WebForms Control`s to make life easier for WebForms users.

Our questions:

  1. Where should we call the code to map interfaces with concrete classes for the core library? It has no single entry point, there are numerous classes which may be instantiated first.

    Currently we force the user to call DependencyHandler.Init() before doing any other library call. Is there a nicer way, like a piece of code which gets executed after loading the DLL so that we won’t force the user to write one line of boiler-plate code?

  2. Which is the recommended way to let library users change an interface implementation into their own type? Currently the user may retrieve the Registry by StructureMap.Configuration.DSL.Registry theRegistry = DependencyHandler.Instance().GetConfiguration() and then change things by for example theRegistry.For<IFoo>().Use<MyOwnFooImplementation>(); Would it be nicer to use XML? And if so, where should we put said XML? We choose the programmatic approach as Visual Studio will be able to give the user some help.

  3. If the current approach in 2 above is used, the library user is required (at least now) to add a Reference to StructureMap.DLL as well as to our DLL. Could we remove that burden from the user, maybe by using XML for dependency setup instead?

  4. Is there a nice central location in WebForms we should use, which solves problem 1 for the WebForms library DLL?

  5. How do you recommend we structure things for production and test?

    The current idea is to use DI in all places necessary to enable Unit Testing where we and supposedly our users want it, as well as enabling the users to change the library behavior by providing their own implementations.

    To test things, we and the library users will have to create mock classes to replace dependencies we want to break away. The idea is that we use the normal configuration but override the classes we want to mock instead of using their normal implementation. Is that a good way to proceed?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:45:13+00:00Added an answer on May 17, 2026 at 10:45 pm

    It’s important to note that in order to provide an API from which others can isolate their code you need to make sure that they can depend on abstractions rather than concrete implementations. That is, as long as the classes that you exposes that “do stuff” either implements an interface (usually best), inherits from an abstract class which defines the interface or have all their public members as virtual (usually worst) I, as a consumer of your API, is able to isolate my code from your concrete implementations.
    In other words, you using an IoC-container in it self isn’t key to providing a testable API. But making your classes non-static and as implementations of abstractions is.
    Using a container has many other benefits though. For instance you will probably have a much easier time testing the various classes in your API yourselves 🙂

    1. There is no single entry point, but to use your API I would instantiate one or several classes right? Each of those classes could have constructors which require the client to provide concrete implementations of the abstractions on which the class is dependent. To avoid forcing clients to specify which implementations to use you could also provide parameterless constructors which use the default implementations.

    2. It depends, but anything from your approach to a simple DSL for wiring up the API to configuration files can be fine. In general though, as I said before, clients probably wont be very interested in changing the implementations that your classes depend upon as long as they themselves can isolate their own code from your “top-level” classes.

    3. Application start is probably a good place for this. The Web Forms library could be an HttpModule or you could provide default boot strapping and instruct clients to make any changes that they need to make in the application start event in global.asax.

    4. Sounds good. Like I said before, I think the most important thing is that your classes and their methods aren’t static (and preferably not singletons) and that their interfaces is defined in an abstract way, thus enabling people to provide use other concrete implementations for testing.

    I might have misunderstood a few things, but I hope my answers might help at least a little 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a .net webAPI project where we are using dependency injection (StructureMap
I am thinking about using Microsoft Unity for my Dependency Injection tool in our
I'm using StructureMap for dependency injection and I want to inject NHibernate sessions with
I'm trying to follow this tutorial using StructureMap : http://iridescence.no/post/Constructor-Injection-for-ASPNET-MVC-Action-Filters.aspx What I'm trying to
We are using StructureMap to cache a a class by InstanceScope.HttpContext. When unit testing
Currently I'm trying to understand dependency injection better and I'm using asp.net MVC to
In Using StructureMap 2.5 to scan all assemblies in a folder , we can
I'm currently using StructureMap to inject instances of NHibernate ISessions using the following code:
I have an asp.net mvc2 application that is using StructureMap 2.6 and NHibernate 3.x.
I'm on an MVC3 project and I am using snap structuremap for my dependecy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.