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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:16:54+00:00 2026-06-11T07:16:54+00:00

I have been doing a lot of reading and tutorials on Dependency Injection via

  • 0

I have been doing a lot of reading and tutorials on Dependency Injection via Ninject in the hopes of re-factoring one of my applications to be more flexible and scalable in the future. My web app is built on top of an API that gives me access to the back-end infrastructure.

Part of my technical debt that I’m trying to clear up is the repeated code that comes with every single API call that I have to make. The API has about 45-50 methods for fetching and managing different entities.

The following (greatly simplified) code example illustrates a recurring pattern that is found everywhere in my code. Can Ninject/DI help make things easier for me?

namespace MyApp
{
public class example
{
    public  static WebAccount Fetch_Account(Guid accountID)
    {
        //Create instance of API, request and response objects
        WebAPI api = new WebAPI();
        Fetch_Account_Request accountRequest = new Fetch_Account_Request();
        Fetch_Account_Response accountResponse = new Fetch_Account_Response();

        //Api call security signature
        ApiSecuritySignature signature = new ApiSecuritySignature(/*My API ID */, /*My API Key */);

        accountRequest.API_ID = /* My API ID */;
        accountRequest.Token = signature.Token;
        accountRequest.TimeStamp = signature.Date;

        //Id of the account to be fetched
        accountRequest.Account_ID = accountID;

        //Fetch the account
        accountResponse = api.Fetch_Account(accountRequest);

        return accountResponse.Account;
    }


    public static void Manage_Account(WebAccount account)
    {
        //Create instance of API, request and response objects
        WebAPI api = new WebAPI();
        Manage_Account_Request manageAccountRequest = new Manage_Account_Request();
        Manage_Account_Response manageAccountResponse = new Manage_Account_Response();


        //Api call security signature
        ApiSecuritySignature signature = new ApiSecuritySignature(/*My API ID */, /*My API Key */);

        manageAccountRequest.API_ID = /* My API ID */;
        manageAccountRequest.Token = signature.Token;
        manageAccountRequest.TimeStamp = signature.Date;

        //account to modify
        manageAccountRequest.Account_ID = account.Account_ID;

        //set Account properties
        manageAccountRequest.Email =  account.Email;
        manageAccountRequest.Address_1 =  account.Address_1;
        manageAccountRequest.City = account.Postal_Zip;
        manageAccountRequest.Postal_Zip = account.Postal_Zip;
        manageAccountRequest.Country = account.Country;
        manageAccountRequest.State = account.State;

        //Make the call
        manageAccountResponse = api.Manage_Account(manageAccountRequest);
    }
}
}

It should be noted that I do not have access to the code for all of the request and response objects, they are part of a shared library that I reference.

  • 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-11T07:16:56+00:00Added an answer on June 11, 2026 at 7:16 am

    Dependency injection per se wont help you. It’s job is just to make sure that the dependencies gets supplied (instead of letting the class itself create them).

    An IoC container just takes care of when objects should be created and disposed i.e. the object lifetimes. (dependency injection is a bonus that you get)

    The proper solution for you is to use the factory method pattern.

    You can create an interface like:

    public interface IWebApiFactory
    {
        Fetch_Account_Request CreateAccountRequest();
    }
    

    so that you’re code can be simplied to:

    public  static WebAccount Fetch_Account(Guid accountID)
    {
        var request = _factory.CreateAccountRequest();
        request.Account_ID = accountID;
        var response = api.Fetch_Account(accountRequest);
        return accountResponse.Account;
    }
    

    Then you can of course inject the IWebApiFactory class into the example class.

    A side note: If you are using DI/IoC you should avoid static classes as much as you can.

    You might be interested in reading my IoC articles (to understand IoC/DI better):

    • http://www.codeproject.com/Articles/386164/Get-injected-into-the-world-of-inverted-dependenci
    • http://www.codeproject.com/Articles/440665/Having-fun-with-Griffin-Container
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been doing a lot of unit testing lately with mocking. The one
So I've been doing a lot of reading. And I have been able to
I have been doing a lot of reading but I have not been able
So I have been doing a lot of reading about the way iOS handles
I have been doing a lot of reading on LINQ to XML but unfortunately
I have been doing a lot of reading on SDL and SFML, and no
I have been doing a lot of reading on this subject and am having
I have been doing a lot of reading but not coming up with any
I have been doing a lot of reading on service layers and business layers
I have been doing a lot a reading about unit testing. Unit testing seems

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.