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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:31:04+00:00 2026-05-22T11:31:04+00:00

I have more like desing question as I’m refactoring quite big piece of code

  • 0

I have more like desing question as I’m refactoring quite big piece of code that I took over.

It’s not modular, basically it’s pseudo-object-oriented code. It contains hard coded dependencies, no interfaces, multiple responsibilities etc. Just mayhem.

Among others it contains a great deal of internal calls to class called Audit, that contains methods like Log, Info, LogError etc… That class has to be configured in application config in order to work, otherwise it’s crash. And that’s the main pain for me. And please, let’s focus on that issue in responses, namely making client code independent of logging classes/solutions/frameworks.

And now, I would like those classes, that have that Audit class dependency hardcoded, refactored in order to obtain several benefits:

  1. First is to extract them nicely to different assemblies, as I will need some functionality available in other applications (for instance generating attachments code – let’s call it AttachmentsGenerator class, that until now was specyfic to one application, but now that code could be used in many places)
  2. Remove internal dependencies so that other application that will take advantage of my AttachmentsGenerator class without the need to add reference to other
  3. Do a magic trick in order to allow AttachmentsGenerator class to report some audit info, traces etc. But I don’t want it to have hardcoded implementation. As a matter of fact, I don’t want it to be mandatory, so it would be possible to use AttachmentsGenerator without that internal logging configured and without the necessity for the client code to add reference to another assemblies in order to use logging. Bottom line: if client code wants to use AttachmentsGenerator, it adds reference to assembly that contains that class, then it uses new operator and that’s all.

What kind approach can I use in terms of design patterns etc to achieve it? I would appreciate some links to articles that address that issue – as it can be timeconsuming to elaborate ideas in answer. Or if you can suggest simple interface/class/assembly sketch.

Thanks a lot,
Paweł

Edit 1: As my question is not quite clear, I’ll rephrase it once again: This is my plan, are there other interesting ways to do this?

  • 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-22T11:31:05+00:00Added an answer on May 22, 2026 at 11:31 am

    Seems like the easiest way to do this would be to use dependency injection.

    1. Create a generic ILogger interface with methods for logging.

    2. Create a concrete implementation of ILogger that just does nothing for all the methods (e.g. NullLogger)

    3. Create another concrete implementation that actually does logging via whatever framework you choose (e.g. log4net)

    4. Use a DI tool (spring, structure map, etc.) to inject the appropriate implementation depending on whether or not you want logging enabled.

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

Sidebar

Related Questions

I have code that looks more or less like the code below but it
I would like to have more than one button. I tried to copy code
I have a custom dataGrid that acts more like a 2D list (if that
I have read that most languages are becoming more and more like lisp, adopting
i have a question that is more design and architecture related. I am coming
This is more of a design question. Suppose you have a method like this
This is more or less a design question. we have to process like a
This is more of a design question that others may have had similar experience
I have a conceptual question that I'm hoping someone more versed in sql database
I have three checkboxes like ch[0], ch[1] and ch[3] (sometimes i have more, or

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.