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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:23:15+00:00 2026-06-12T08:23:15+00:00

I have an interface INetworkAware and need to declare method which will forece every

  • 0

I have an interface INetworkAware and need to declare method which will forece every class to register for events

currently using prisms eventaggregator our implementation is the following.

    protected override void SetupEvents()
    {
        RegisterForEvent<PatientSelected>(OnPatientSelected);
        base.SetupEvents();
    }

SetupEvents method is declared as virtual in ViewModelbase class. in out situation we want to have above mentioned INetworkAware interface and in addition to deriving from ViewModelBase if any class is interested in listening to network changes(network offline/online) and implement INetworkAware interface we want to have mechanism to force them to register for this event using same principals.
so for example if we create class

public class PatientInformationViewModel : ViewModelBase, INetworkAware
{
     protected override void SetupEvents()
     {
         RegisterForEvent<PatientSelected>(OnPatientSelected);
         base.SetupEvents();
     }

     INetworkAware.ListenForNetworkChange
     {
         RegisterForEvent<NetworkChangeEvent>(OnNetworkChange)
     }

     OnNetworkChange(NetworkChangeEvent networkstatus)
     {

     }
 }

NetworkChangeEvent is a sample POCO class

INetworkAware.ListenForNetworkChange and OnNetworkChange(NetworkChangeEvent networkstatus) must be implemented in every viewmodel deriving from INetworkaware and with the same signature.

houw can we accomplish this scenario

  • 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-12T08:23:16+00:00Added an answer on June 12, 2026 at 8:23 am

    You are almost on the right track. If you implement the interface on the base class and then declare your method as abstract in the base class that will force any extending (deriving) class to implement it’s own version:

    public abstract class ViewModelBase : INetworkAware
    {
    
        public abstract void SetupEvents();
    
    }
    
    public class PatientInformationViewModel : ViewModelBase
    {
        public override void SetupEvents()
        {
            //register for your events
        }
    }
    

    Alternatively you can declare the method in the base class as virtual rather than abstract and provide a base implementation, and your derived classes can simply override this when necessary. I’ve used this pattern before myself and it is quite effective – just make sure you include an Unsubscribe() (or similar) on the interface as well.

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

Sidebar

Related Questions

I am planning to develop a site which will have interface very similar to
I have interface IConfigurationSource { .... } and class FileConfigurationSource : IConfigurationSource { FileConfigurationSource(string
I have interface Foo public interface Foo { public void test(); } Class FooChild
I have interface IModule and several classes that implements it. In test i need
Assume I have interface and class: public interface ITree {} public class Tree :
For example I have interface ICommand {} class MovePiece : ICommand {} class Successful<CMD>
I know that that on can have a class declaration in a method of
lets say I have an NSWindow Class, that has several events for mouse and
i have interface: public interface Inx<T> { T Set(Data data); } simple class with
Suppose I have: interface Foo { void doStuff(); } class FooImpl implements Foo {

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.