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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:43:07+00:00 2026-05-24T08:43:07+00:00

I have the following interfaces and classes: public interface ILoggingService { … } public

  • 0

I have the following interfaces and classes:

public interface ILoggingService { ... }
public class LoggingService {
    public LoggingService(ILoggingRepository loggingRepository) { ... }
    ...
}

public interface ILoggingRepository { ... }
public class DatabaseLoggingRepository {
    public DatabaseLoggingRepository(string ConnectionString) { ... }
    ...
}
public class FileLoggingRepository {
    public FileLoggingRepository(string LogFilePath) { ... }
    ...
}

I’m refactoring my software to use Unity IoC framework and am looking for a way to pass the specific configuration to each ILoggingRepository implementation.

I think that the best way would be to change DatabaseLoggingRepository’s and FileLoggingRepository’s constructors to have no parameters at all and have them configured by some configuration file. However, because of my acceptance tests I would need a easy way to override these settings while running my tests.

Am I on the right track and if I am, which configuration files should I use? Alternative ways are welcome as well.

  • 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-24T08:43:08+00:00Added an answer on May 24, 2026 at 8:43 am

    What we’ve decided to do is create a class, in your case it would be LoggingConfiguration, and have that passed to the constructo of the repository. If you resolve using Unity it will instantiate this class using Activator, wuthout having to register it. In your tests however, you just greate a new instance of a derived configuration class, providing different values.

    Does it makes sense? Should I clarify more?

    Update: I’ve decided to provide some additional clarification. So, you already have two implementations, and now you want each configuration to query for its proper configuration setting.

    I would extend the ILoggingRepository‘s constructor to look like this:

       public ILoggingRepository(ILoggingConfigurationProvider confProvider);
    

    You can then create one implementation for your normal operation which has two properties:

    public LoggingConfigurationProvider : ILoggingConfigurationProvider {
     public LoggingConfigurationProvider() {
       // load both values from configuration file
     }
    
     public string LogPath { get; set; }
     public string ConnectionString { get; set; }
    }
    

    When you instantiate your class via normal IoC operation this will get resolved by the container and you’ll configuration options will get loaded from the conf file. When you however want to do Unit tests you:

    1) Create a new “Mock” implementation

    public class MockLoggingConfigurationProvider : ILoggingConfigurationProvider  {
       public MockLoggingConfigurationProvider() {
          // set both values to a test value
       }
    
       public string LogPath { get; set; }
       public string ConnectionString { get; set; }
    }
    

    Now you can either create the repository using a constructor:

    new LoggingRepository(new MockLoggingConfigurationProvider());
    

    or if you want the whole IoC mechanism to be used, you simply (when setting up the container) register this implementation of the interface. Because the unit tests are separate, you don’t share the registrations right? So that should give you what you need, the ability to change this settings depending on weather they are being executed as a unit test or not.

    In real life, I wouldn’t even bother with this, and just create a mock logging repository and have it write somewhere else. Unless you want to test the repository to a test database/file. In which case I’d do as specified.

    Hope it helps.

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

Sidebar

Related Questions

I have the following set of Interfaces and Classes. public interface IValidatableObject { List<string>
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
I have the following classes defined: public interface Thingy { ... } public class
I have the following classes / interfaces: public interface IProjectRepository { IQueryably<Project> GetProjects(); }
I have following Classes and interfaces.. public interface ITaggable { ICollection<Tag> Tags { get;
I have the following classes: public interface Emailer {} @Named public class RealEmailer implements
I have the following Interfaces: public interface ITemplateItem { int Id { get; set;
Example, I have the following interface and classes: public interface IRole { DateTime Since
I have the following hierarchy of classes: public interface Message public interface V2Message extends
I have the following classes : public interface Factory<T extends MyParentClass> { public T

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.