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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:45:53+00:00 2026-05-24T19:45:53+00:00

I have a occasionally connected application where there is a server that stores information

  • 0

I have a occasionally connected application where there is a server that stores information about products. I am using a database cache to store this information locally so when a connection is unavailable the application will still work when trying to read the database.

Since the database is configured and I do not have access to modify the tables, I did not implement 2 way updating and it only downloads a snapshot. A side question is if it is possible to create a database cache and have 2-way sync with only tracking columns on the client machine? I cannot add any columns or tables to the server. I know this might be a question for a separate post, but if this is true then it would change my direction for this problem completely, to a separate module detecting and syncing the database and handling any sync errors that are thrown and always connecting to the cache.

I am using a generic repository and I am wondering what the best practice to go about handling if a connection is available or not and using either a local or remote database depending on this status.

Should I add an interface to the generic repository that handles returning the correct string, and lets the repository know if it is live or not? I need to enable/disable certain features depending on the connection state so I also will need a property somewhere so that when this repository is used there can be a way to bind various controls enabled state to this status.

Instead should I have a wrapper that contains for example an IRepository and IConnectionStringManager and then handles feeding and initializing the repository connection string based on availability? This wrapper would expose the repository and any status properties required.

I guess I am not sure if I should be setting up my program to use IRepository with all the automatic connection sensing behind the scenes, or if I should have IRepositoryManager that has a IRepository and IConnectionStringManager in it.

Maybe both of those options are wrong?

  • 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-24T19:45:55+00:00Added an answer on May 24, 2026 at 7:45 pm

    I like the way Entity Framework allows you to provide a connection string as a constructor argument to its contexts. That way you can leverage a dependency injection framework to apply special logic when creating the context, and you only have to change the code in one place (assuming you’re using DI principles). You could do something similar with your repository implementation.

    Update

    Since you’re using Entity Framework, here’s an idea of what it might look like in code:

    // DI Bindings, Ninject style
    Bind<Func<MyContext>>().ToMethod(
        c => new MyContext(
                 c.Kernel.Get<IConnectionManager>().IsOnline()
                     ? OnlineConnectionString 
                     : OfflineConnectionString));
    
    // Usage
    public class ThingRepository : IThingRepository 
    {
        private Func<MyContext> _getContext;
        public ThingRepository(Func<MyContext> getContext)
        {
            _getContext = getContext;
        }
    
        public IEnumerable<Thing> GetAllThings()
        {
            using(var context = _getContext())
            {
                return context.Things.ToList();
            }
        }
    }
    

    Or, if you prefer to use a more explicit factory implementation:

    public interface IMyContextFactory
    {
        MyContextFactory Get();
    }
    
    public class MyContextFactory : IMyContextFactory
    {
        private const string OnlineConnectionString = "...";
        private const string OfflineConnectionString = "...";
        private IConnectionManager _connectionManager;
        public MyContextFactory(IConnectionManager connectionManager)
        {
            _connectionManager = connectionManager;
        }
        public MyContextFactory Get() 
        {
            var connectionString = _connectionManager.IsOnline() 
                ? OnlineConnectionString 
                : OfflineConnectionString
            return new MyContext(connectionString);
        }
    }
    
    // DI Bindings, Ninject style
    Bind<IMyContextFactory>().To<MyContextFactory>();
    
    // Usage
    public class ThingRepository : IThingRepository 
    {
        private IMyContextFactory _myContextFactory;
        public ThingRepository(IMyContextFactory myContextFactory)
        {
            _myContextFactory = myContextFactory;
        }
    
        public IEnumerable<Thing> GetAllThings()
        {
            using(var context = _myContextFactory.Get())
            {
                return context.Things.ToList();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-threaded Windows application that occasionally deadlocks. Inevitably this happens on a
I have a Windows application written in C++ that occasionally evaporates. I use the
I have a server application (singleton, simple .NET console application) that talks to a
We have a client application that needs to send messages to a server for
I have an application that uses sockets to connect to my server. A lot
I have a Delphi application that reads/writes to a COM port connected to a
I am using BSD sockets over a wlan. I have noticed that my server
I have a .net 2.0 application that uses the System.Net.Sockets Send() method to send
I have assisted with an application that has a couple of thousand deployments. This
I have a Cherokee installation that I'm using to serve a few web applications

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.