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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:29:53+00:00 2026-05-29T05:29:53+00:00

I have a code which look something like this. When trying to do a

  • 0

I have a code which look something like this. When trying to do a ResolveAll I expected every type registered with the IParserType to yielded from the container instance. But I didn’t get any instance from Unity. Am I assuming or doing something wrong here.

public class ResolveAllDemo
{
    public ResolveAllDemo()
    {
        var container = new UnityContainer();

        container.RegisterInstance<IUnityContainer>(container);
        container.RegisterType<IParser, SuperParser>();
        container.RegisterType<IParser, DefaultParser>();
        container.RegisterType<IParser, BasicParser>();
        //   container.RegisterType<Crawler>();
        container.RegisterType<IParserFactory, UnityParserFactory>();

        foreach (var registeredMember in container.ResolveAll<IParser>())
        {
            LoggingUtility.LogerInstance.Logger.Write(registeredMember);
        }
    }

    #region Resolve Demo

    public interface IParserFactory
    {
        IEnumerable<IParser> BuildParsers();
    }

    public class UnityParserFactory : IParserFactory
    {
        private IUnityContainer _container;

        public UnityParserFactory(IUnityContainer container)
        {
            _container = container;
        }

        public IEnumerable<IParser> BuildParsers()
        {
            return _container.ResolveAll<IParser>();
        }
    }

    public class DefaultParser : IParser
    {
        public override string ToString()
        {
            return "DefaultParser";
        }
    }

    public class BasicParser : IParser
    {
        public override string ToString()
        {
            return "BasicParser";
        }
    }

    public class SuperParser : IParser
    {
        public override string ToString()
        {
            return "SuperParser";
        }
    }

    public interface IParser
    {
    }

    #endregion Resolve Demo
}
  • 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-29T05:29:54+00:00Added an answer on May 29, 2026 at 5:29 am

    You are not registering 3 different implementations of IParser. You create one default mapping IParser -> SuperParser and then overwrite it with IParser -> DefaultParser and then you overwrite it again with IParser -> BasicParser.

    If you want to register all three of them you have to provide named registrations like

    container.RegisterType<IParser, SuperParser>("Super");
    container.RegisterType<IParser, DefaultParser>("Default");
    container.RegisterType<IParser, BasicParser>("Basic");
    

    In addition ResolveAll does not include the default mapping (the one without a name). It only resolves those mappings of IParser that were registered as named mappings.

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

Sidebar

Related Questions

I have code which needs to do something like this There is a list
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have code which as been working against an older Active Directory server and
I already have code which lazy loads scripts on request. My issue now is
I have some code which collects points (consed integers) from a loop which looks
I have have some code which adds new cells to a table and fills
I have some code which utilizes parameterized queries to prevent against injection, but I
I have some code which I am making available via RMI. If my program
I have some code which needs to ensure some data is in a mysql
I have some code which returns InnerXML for a XMLNode. The node can contain

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.