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

  • SEARCH
  • Home
  • 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 1077817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:37:57+00:00 2026-05-16T21:37:57+00:00

I’m facing some architectural problems on the project I’m involved in. The project is

  • 0

I’m facing some architectural problems on the project I’m involved in. The project is an ASP.NET MVC 2 application that relies on DI and especially on constructor injection with Unity. The application is divided into several modules (each module is a set of assembies) that exposes services to other modules. Those services are registered to Unity at application startup. Nothing special untill now. Let’s say I have this (each module is an assembly for simplification) :

ModuleA, ModuleB.

ModuleA exposes a service ‘IServiceA’ with the following methods :

IServiceA (Operation1 – Operation2 – Operation3)

ServiceB from ModuleB needs IServiceA from ModuleA and it gets it by the constructor injection (with concrete implementation). Then it uses it.

The problem is when ModuleA is desactivated (we check in the database if the module is acivated for the current user at application startup) so the serviceA is not registered with Unity.

Then we have an exception at runtime because unity can’t find a registration for a IServiceA and ServiceB cannot be constructed. Which is normal.

I would like to know it there is a set of patterns or the best practice to deal with it. My first though was to get rid of constructor injection for ServiceB. But then I should use the hard reference to the ServiceA and I don’t like it or to use a ServiceLocator which is even worse. I don’t want to check in ModuleB if ServiceA is available or not, because there will be many other services I would check and should deal with a code thats pure infrastructural. I would like that ServiceB runs the same code if the serviceA is available or not (don’t know if possible). I looked at a Gateway pattern but don’t know if this can help me.

Any help will be appreciated.

Thanks,

  • 1 1 Answer
  • 0 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-16T21:37:57+00:00Added an answer on May 16, 2026 at 9:37 pm

    You’ll need some sort of default implementation that can take over when ModuleA is deactivated. The Null Object pattern sounds like a perfect fit.

    Just register your NullServiceA with Unity first. This will be the default IServiceA unless overwritten by the real implementation (let’s call it ConcreteServiceA).

    For a more sophisticated implementation, you can wrap NullServiceA and ConcreteServiceA in a Composite, or perhaps another form of Decorator that chooses one over the other based upon availability.

    You could, for example, have a Composite that always uses the first (or the last) of the IServiceA instances injected into it… or perhaps the selection criterion could be based upon some sort of metadata that determines whether the module is activated or deactivated (sounds like that information itself could fit well into a hypothetical IModule interface).

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

Sidebar

Related Questions

No related questions found

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.