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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:27:49+00:00 2026-06-02T08:27:49+00:00

I have created a service data access layer where there are multiple databases where

  • 0

I have created a service data access layer where there are multiple databases where data needs to come from.

I was doing fine with one database where I defined the memberRepository that contained member details. However, now I have to get session-related details that are stored in another database.

OprationContracts:

  • IMemberServices contains GetLoggedInBuddies(int profileID);
  • ISessionServices contains GetProfileIDFromSessionID(string sessionID);

My service class:

public class MemberService : IMemberService, ISessionServices
{
    #region Strategy pattern configuration

    //
    // Member repo
    // 
    private MemberRepository memberRepository;
    public MemberService()
        : this(new MemberRepository())
    { }
    public MemberService(MemberRepository memberRepository)
    {
        this.memberRepository = memberRepository;
    }


    //
    // Session repo
    //
    private SessionRepository sessionRepository;
    public MemberService() : this(new SessionRepository()){}
    public MemberService(SessionRepository sessionRepository)
    {
        this.sessionRepository = sessionRepository;
    }

    #endregion



    /// <summary>
    /// Session-related details are maintained in the Secondary database
    /// </summary>
    /// <param name="sessionID"></param>
    /// <returns></returns>
    public int GetProfileIDFromSessionID(string sessionID)
    {
        int sessionProfileID = sessionRepository.GetProfileDetailsFromSessionID(sessionRepository);

        return sessionProfileID;
    }

    /// <summary>
    /// Try profileID = 1150526
    /// </summary>
    /// <param name="profileID"></param>
    public void  GetLoggedInBuddies(int profileID)
    {
        memberRepository.GetLoggedInBuddies(profileID);
        //return memberRepository.GetLoggedInBuddies(profileID);
    }

The issue is that in the // Session Repo section, as I already have a constructor defined. I get that.

So basically in each method I want to do something like

MemberService useSessionRepo = new MemberService(SessionRepository);
useSessionRepo.GetProfileDetailsFromSessionID(...);

MemberService useMemberRepo = new MemberService(MemberRepository);
useMemberRepo.GetLoggedInBuddies(...);

Just need a hand putting this together.

Thanks.

  • 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-02T08:27:51+00:00Added an answer on June 2, 2026 at 8:27 am

    I created a central repository that accepts the name of the connection string of the database I want to connect to.

    public abstract class DatabaseRepository : BaseRepository
    {
        static IDbConnection connection;
    
        /// <summary>
        /// Handles db connectivity as Dapper assumes an existing connection for all functions
        /// Since this app uses three databases, pass in the connection string for the required db.
        /// </summary>
        /// <returns></returns>
        protected static IDbConnection OpenConnection(string connectionStringName)
        {
            try
            {
                connection = new SqlConnection(WebConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString);
                //connection = SqlMapperUtil.GetOpenConnection(connectionStringName);       // if we want to use the Dapper utility methods
                connection.Open();
                return connection;
            }
            catch (Exception ex)
            {
                ErrorLogging.Instance.Fatal(ex);        // uses singleton for logging
                return null;
            }
        }
    .
    .
    .
    

    Then in my service library, I make the connection to the appropriate db and perform whatever queries I need:

    using (IDbConnection connection = OpenConnection("FirstDBConnectionString")) { ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Data Access Layer, a Service Layer, and a Presentation Layer. The
I have a Data Service created using WCF that internally uses nHibernate. This WCF
I have created a web service which is saving some data into to db.
I have created a web service which returns some data and am trying to
I have created a Windows Service in VB.net for building xML from a database.
I've implemented the repository pattern on the data access layer of our current service
I have a data access layer which returns an IDataRecord. I have a WCF
I have been having some issues retrieving JSON data from a WCF service application
I have an application that is currently divided into Service and Data Access Layers
I have a WCF service that uses LINQ to SQL for its data layer.

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.