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 7546321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:10:08+00:00 2026-05-30T09:10:08+00:00

_container.RegisterType<TypeA>(); _container.RegisterType<TypeC>(); // TypeC has a dependency to TypeA _container.RegisterType<TypeD>(); // TypeD has a

  • 0
_container.RegisterType<TypeA>();
_container.RegisterType<TypeC>(); // TypeC has a dependency to TypeA
_container.RegisterType<TypeD>(); // TypeD has a dependency to TypeA

_container.RegisterType<TypeE>(); // TypeE has a dependencies to TypeC and TypeD
_container.RegisterType<TypeF>(); // TypeF has a dependencies to TypeC and TypeD

How do I set this up so that when I create types E and F they both use a new instance of TypeA (indirectly through types C and D) but C and D both use the same TypeA?

If it helps imagine that TypeA is a repository and C and D are services that use that repository. Types E and F are ViewModels that need different repositories but interact with the repository through services C and D.

I imagine I could resolve typeA and then use that instance to resolve the other types but I’m guessing there is a better way, as that seems quite messy.

  • 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-30T09:10:10+00:00Added an answer on May 30, 2026 at 9:10 am

    Take a look at my answer to your second question here.

    By using a PerResolveLifetimeManager, when TypeE is resolved, TypeE and its dependencies TypeC and TypeD all get the same instance of TypeA. When TypeF is resolved, a new TypeA is resolved, which it and all of its dependencies will share.

    PerResolveLifetimeManager is one of my favorite things about Unity as an IOC container over others.

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

Sidebar

Related Questions

Suppose I have two types, TypeA and TypeB, that I want to register with
This is a fairly straight forward decorator pattern scenario, with the complication that the
I have an interface to resolve and one of the mapped object's dependencies has
I'm trying to inject a dependency to my MVC controllers like this private static
I've created an ISearchable interface that I've Typed so that I can retrieve an
I'm trying to invoke the RegisterType method in the Unity container. RegisterType has a
I have a custom type instance that needs to be registered in code: container.RegisterType(
I can't figure out how to register a generic abstract class that has a
$(.container).hover( function(){ $(.child-1).hide(0); $(.child-2).show(0); },function(){ $(.child-1).show(0); $(.child-2).hide(0); }); A project I have requires that
I need an associative container that makes me index a certain object through a

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.