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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:13:05+00:00 2026-06-16T23:13:05+00:00

I have a scenario using Unity which is a bit confusing… Say I have

  • 0

I have a scenario using Unity which is a bit confusing… Say I have an AuthenticationService that authenticates users and when successful logs to a text file or database using TextLogger class or DbLogger class respectively. Normally for which ever class I will use in my project I would register appropriately in my module class as below:

public class LoggingModule
{
    IUnityContainer _iocContainer;

    public LoggingModule(IUnityContainer container)
    {
        _iocContainer = container;
    }

    public void Init()
    {
        //Add any logic here to look in a config file, check a property
        //or any other condition to decide which implementation is registered.

        //register the database logger to the ILogger interface
        _iocContainer.RegisterType(typeof(ILogger), typeof(DBLogger));

    }
}

And this will be injected into the constructor of my Authentication Service. However if I wanted to use both loggers at different points in my application, first do I Register both types in my Init method, i.e. the TextLogger and DBLogger?
Second, how does my container know which type to Resolve?

Please help….

  • 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-06-16T23:13:07+00:00Added an answer on June 16, 2026 at 11:13 pm

    Register your both types into container with a name, i.e.;

    container.RegisterType<ILogger, DBLogger>("DBLogger");
    container.RegisterType<ILogger, TextLogger>("TextLogger");
    

    and resolve your types using the name parameter, i.e.;

    var logger = container.Resolve<ILogger>("DBLogger");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Scenario Using jQuery, I have a page that has a popup overlay containing
I have a scenario that when I try to access a hash key using
I have a scenario where i have one control, which is using another control
I have a scenario that looks like this: #include <algorithm> using namespace std; //
I have a scenario where I am using Google Map JavaScript API to process
I have a scenario where people login to the IM we developed using the
I have a scenario where I need to search from many binary files (using
I have a scenario where I am to send email using our own SMTP
I have this scenario where I would like to redirect my domains using the
I am using silverlight 4. I have a scenario where i need to compare

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.