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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:35:59+00:00 2026-06-18T03:35:59+00:00

I have two .NET parties who needs be bound by a contract. Now, party1

  • 0

I have two .NET parties who needs be bound by a contract. Now, party1 and party2 need to be able call some methods on each other (most of it is calls and reporting result back). I have duplex contract in mind, but the parties are not using WCF.

Is there a design pattern for this?

Edit

The parties are part of the same application. I create the application (party1) and someone else creates a dll (party2) that I load dynamically. Now, both of us should be able to call methods on each other. So, I am out to create an interface contract between us. The intent is to know whether there is a know pattern to do that?

  • 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-18T03:36:00+00:00Added an answer on June 18, 2026 at 3:36 am

    A common solution is to use some kind of pub/sub pattern. By doing so you can avoid circular dependencies.

    Basically you create some kind of class which are used to subscribe on events (and publish them).

    So both your classes does something like this (but with different events):

    public class ClassA : IEventHandler<UserCreated>
    {
        IEventManager _eventManager
    
        public ClassA(IEventManager manager)
        {
           // I subscribe on this event (which is published by the other class)
           manager.Subscribe<UserCreated>(this);
           _eventManager = manager;
        } 
    
        public void Handle(UserCreated theEvent)
        {
            //gets invoked when the event is published by the other class
        }
    
        private void SomeInternalMethod()
        {
            //some business logic
    
            //and I publish this event
            _eventManager.Publish(new EmailSent(someFields));
        }
    }
    

    The event manager (simplified and not thread safe):

    public class EventManager
    {
        List<Subscriber> _subscribers = new List<Subscriber>();
    
        public void Subscribe<T>(IEventHandler<T> subscriber)
        {
            _subscribers.Add(new Subscriber{ EventType = typeof(T), Subscriber = subscriber});
        }
    
        public void Publish<T>(T theEvent)
        {
            foreach (var wrapper in subscribers.Where(x => x == typeof(theEvent)))
            {
                ((IEventHandler<T>)wrapper.Subscriber).Handle(theEvent);
            }
        }
    }
    

    The small wrapper:

    public class Subscriber
    {
        public Type EventType;
        public object Subscriber;
    }
    

    Voila. the two classes are now loosely coupled from each other (while still being able to communicate with each other)


    If you use an inversion of control container it get’s easier since you can simplify the event manager and just use the container (service location) to resolve all subscribers:

    public class EventManager
    {
        IYourContainer _container;
    
        public EventManager(IYourContainer container)
        {
            _container = container;
        }
    
        public void Publish<T>(T theEvent)
        {
            foreach (var subscriber in _container.ResolveAll<IEventHandler<T>>())
            {
                subscriber.Handle(theEvent);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two asp.net textboxes and need to put a validate function in javascript
We have a customer who have two .NET assemblies, A and B: Assembly A
I now have two asp.net pages. When I click on a link on page
I have two functions written in VB.NET: 1) The first function (call it GetValues())
I have two asp.net pages and navigating from Page1 to Page2 takes some times.
We have two thick-client .NET applications that need to send messages to each other
I have two problems with my Page right now http://jsfiddle.net/aE2BB/1/ 1st when I hover
I have two web applications and both are developed in ASP.NET. Now I want
Suppose you have two seperate ASP.NET Web Application projects that both need to use
I have two .NET applications that talk to each other over a named pipe.

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.