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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:15:21+00:00 2026-06-10T14:15:21+00:00

Problem : in my domain layer assembly I store two interfaces: public interface IDomainEvent

  • 0

Problem:

in my domain layer assembly I store two interfaces:

public interface IDomainEvent { }

and

public interface IHandle<T> where T: IDomainEvent, new()

EventDispatcher class is defined there also:

public static class EventDispatcher {
    [ThreadStatic]
    private static List<Delegate> actions;
    [ThreadStatic]
    private static List<Object> handlers;

    public static List<Object> Handlers { 
        get { return handlers; } 
        set { handlers = value; } 
    }

    public static void Register<T>(Action<T> callback) where T : IDomainEvent, new() {
        if(null == actions) {
            actions = new List<Delegate>();
            actions.Add(callback);
        }
    }

    public static void ClearCallbacks() {
        actions = null;
    }

    public static void Raise<T>(T @event) where T : IDomainEvent, new() {
        if(null != Handlers) {
            foreach(var handler in Handlers.Where(h => h is IHandle<T>)) {
                ((IHandle<T>)handler).Handle(@event);
            }
        }

        if(null != actions) {
            foreach(var action in actions) {
                if(action is Action<T>) {
                    ((Action<T>)action)(@event);
                }
            }
        } // if(null != actions) {
    }
}

There’s a module in presentation layer assembly:

public class EventDispatchingModule : NinjectModule {

    public override void Load() {

        // EventDispatcher.Handlers = this.Kernel.GetAll(IHandle<T>); Can't do that!
        // Bind<IHandle<CarHasBeenRegisteredEvent>>().To<CarHasBeenRegisteredHandler();
    }
}

So I can’t call Kernel.GetAll(IHandle<T>) there because it can’t resolve T parameter.

Howcome I resolve this?

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-10T14:15:23+00:00Added an answer on June 10, 2026 at 2:15 pm

    No need to use a module (I’ve not used ninject, but something similar):

    // Put these in the domain project
    
    public class EventDispatcher
    {
        private static IEventDispatcher _dispatcher;
    
        public static void Setup(IEventDispatcher dispatcher)
        {
            _dispatcher = dispatcher;
        }
    
        public static void Dispatch<T>(T domainEvent) where T : IDomainEvent
        {
            _dispatcher.Dispatch<T>(domainEvent);
        }
    }
    
    public interface IEventDispatcher
    {
        public void Dispatch<T>(T domainEvent) where T : IDomainEvent;
    }
    
    
    // and this one in the project which has Ninject
    
    public class NinjectEventDispatcher : IEventDispatcher
    {
        private static IKernel _container;
    
        public NinjectEventDispatcher(IKernel container)
        {
            _container = container;
        }
    
        public void Dispatch<T>(T domainEvent) where T : IDomainEvent
        {
            foreach (var listener in _container.GetAll<IHandle<T>>())
            {
                listener.Handle(domainEvent);
            }
        }
    }
    
    // And after the container have been configured:
    EventDispatcher.Setup(new NinjectEventDispatcher(_container));
    

    But I don’t know how ninject handles scoped objects (which may also want to receive the events).

    My container has domain events built in, read more in this article: http://www.codeproject.com/Articles/440665/Having-fun-with-Griffin-Container

    Update:

    I’ve updated the code sample to make the domain project unaware of Ninject.

    You are not using Service Location with this code. The internals of the event dispatcher is. i.e. none of your code is affected by it.

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

Sidebar

Related Questions

Problem Domain: I am working on a new revision of a Java application that
I just referenced my application domain layer dll to the new WCF service that
I am writing an object conversion class, used to convert domain layer objects into
Problem: to get the command working here. My domain is http://cs.edu.com/user/share_dir , but I
I have a problem with the code analysis rule CA1726:UsePreferredTerms . Our business domain
So here is my problem. I want to redirect name.domain.com/trips/1 to domain.com?username=name&trip=1 using modrewrite.
I have been spending some time on this. My problem involves bringing back domain
Problem: I've written State Machine for my android application. It is separate class, extension
I have a Java application where the domain layer is decoupled from the UI
It is said that the Domain Model is used to capture the problem domain

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.