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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:58:46+00:00 2026-06-12T05:58:46+00:00

I am developing against a system which provides a web service for access to

  • 0

I am developing against a system which provides a web service for access to its database and exposes that through .NET classes. Our usual way of working is to create an instance of the web service class whenever we need to access the database and directly use that instance; this of course completely goes against IoC and creates mostly untestable code. I am now trying to devise a new standard way of working using IoC to enable us to write (more) SOLID code.

My current solution is this (not really well explained):

The web service is wrapped in a DatabaseConnection class that stores the web service object as a protected member and provides access to a number of commonly used general database calls.

When I need database access in an actual application, I derive from that class (calling the new class, say, ApplicationDatabaseConnection) and implement the needed database interactions in methods that then are able to call the web service.

This class is not used directly in the application but provides “connector” interfaces for the different parts of the application, each of which is represented by a controller/view model like class at the top level. Whenever one of these application functions is called (e.g. from the UI), the appropriate controller object is created and passed my ApplicationDatabaseConnection object as an implementation of the respective “connector” interface, so database access is properly encapsulated and decoupled at that point, as far as I can tell.

My issue with this is: While this is the first case where I found actual use for the ISP (interface segregation principle) in my own code (though I’m far from sure whether this actually sensible use of the concept), I’m afraid that this class might do too much and violate the SRP (single responsibility principle). Or is “only providing database access, though for a number of different consumers” a single responsibility?

To maybe make that a bit clearer, here’s roughly what the relevant classes would look like:

DatabaseConnection
    protected m_webservice
    public OftenUsedDatabaseAccess()

ApplicationDatabaseConnection : DatabaseConnection, IConnectorA, IConnectorB
    public IConnectorA.RetrieveRecords(fieldValue)
    public IConnectorB.WriteStuff(listOfStuff)

FunctionAController
    private m_IConnectorA

FunctionBController
    private m_IConnectorB

The alternatives I can think of don’t really seem ideal to me either.

To split up the database access functionality, the ApplicationDatabaseConnection class could only be a factory class with Create methods for the different connectors (behind IConnectorAFactory, IConnectorBFactory interfaces) – but there’s not really anything there to necessitate a factory pattern; there’s nothing I only know when instantiating the “controller” objects.

Also, the actual connector classes would essentially also need to be derivations of DatabaseConnection because they need the same basic abilities, and then (at the latest) the whole construct becomes rather ominous.

I suppose I have taken a wrong turn at some point in my thinking and am now completely on the wrong track. What should the structure of such a solution look like? Any push in the right direction will be greatly appreciated.

Edit:

@Tobias ‘ answer made me realize that I forgot an important detail: There are two different versions of the web service with pretty much the same abilities, but completely different APIs, which is one reason why it has to be encapsulated.

Another one is that if my logic classes access the web service directly (or via an interface), they are also concerned with constructing the web service queries in all their detail, which makes for much more tightly coupled code (the kind we’ve been producing so far) and violates SRP – hence the connector interface idea.

  • 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-12T05:58:47+00:00Added an answer on June 12, 2026 at 5:58 am

    Many months later I know that the “ApplicationDatabaseConnection” approach not only violated SRP, but also OCP while additionally hindering modularization.

    The route I eventually took was a bit similar to the “factory” alternative I described – the “main” DatabaseConnection object is of a subclass that also has a “Create” method that that takes factories for specific DatabaseConnection derivations and doesn’t care about what exactly it creates. That way each controller can request its own connection object, and controllers can be added that the main application doesn’t know about (i.e. via MEF).

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

Sidebar

Related Questions

I am developing my first ASP.Net MVC 3 web application against a SQL Server
I've been developing an ASP .NET 3.5 web application against Cassini, the built-in web
I'm working on a database that is suffering deadlocks. We are developing against the
I am developing a web service that another group is developing a web front
I'm developing against a DB2 database, and at some point I get an error
I am developing / maintaining a tool that allows users to run queries against
I'm developing a standalone application that accesses a common database on a server. It
I have created a dummy web service with 2 optional parameters using the .Net
I am currently developing on an advertising system, which have been running just fine
Im developing a system that uses kinect for image processing. The system needs 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.