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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:47:42+00:00 2026-06-09T09:47:42+00:00

What is the best way to abstract away 3rd party dependencies, when using Ninject

  • 0

What is the best way to abstract away 3rd party dependencies, when using Ninject with ASP.NET MVC?

Usually, I do something like this:

public interface IProductRepository
{
    IEnumerable<Product> GetProducts();
}

public class ProductRespository : IProductRepository
{
    public IEnumerable<Product> GetProducts()
    {
        ...
    }
}

And then in the controller:

public class ProductController : Controller
{
    private IProductRepository repository;

    public ProductController(IProductRepository repository)
    {
        this.repository = repository;
    }

    ...
}

And then I use Ninject to automatically inject the solid ProductRepository into the controller.

But how do I do this if the dependency is 3rd party? For example, I’m using FlickrNet.

public class ProductController : Controller
{
    private Flickr flickr;

    ...
}

I’d like to be able to abstract the Flickr object away into an interface so that I can use dependency injection and make it easier to unit test. I know I could create a ‘service’ type interface and then implement a class based off of that which would wrap the Flickr object.

But I would have to define a member in the interface corresponding to each member of the Flickr object, and then map each of these in the wrapper object. And there are lots and lots of members in the Flickr object.

Is there any better way to deal with this? My main goal is to make it easy to mock the Flickr dependency in unit tests.

  • 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-09T09:47:45+00:00Added an answer on June 9, 2026 at 9:47 am

    Upgraded my comment to an answer.

    This is not a problem with DI but a general architectural problem. You can either declare the controller as your abstraction layer or define a wrapper around the flickr component that implements a custom interface. If the methods on your 3rd party component consume more 3rd party classes you would need to abstract them away too and so on until you are down to only primitive values or more wrappers around 3rd party code. Depending on the complexity of that component this could mean a lot of mapping and wrapping.

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

Sidebar

Related Questions

What is the best way to implement Gather-Scatter like operation using WCF and C#
What would be the best way to abstract away any given JavaScript framework (jQuery,
What's the best way to abstract this pattern: class MyClass attr_accessor :foo, :bar def
What is the best way to autoload abstract classes I have a class Formprocessor_Userregistrate
What is the best way to handle different subtypes of an abstract supertype as
In my ASP.NET MVC 3 application I am to use EF4.3 as an ORM
Which one is the best way of injecting my dependencies? Why? What is the
I'd just like to know the best way of listing all integer factors of
What's the best way to unit test the Serialization of an Exception class like
Given a table like the one below, what would be the best way to

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.