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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:49:03+00:00 2026-05-17T19:49:03+00:00

I am new to structuremap. I am trying to get Structuremap to auto-register public

  • 0

I am new to structuremap. I am trying to get Structuremap to auto-register

public void RegisterAllEventHandlers()
{
    Scan(cfg =>
        {
            cfg.TheCallingAssembly();
            //cfg.IncludeNamespaceContainingType<NewCustomerCreated>();
            cfg.IncludeNamespace("ParentNameSpace");
            cfg.AddAllTypesOf(typeof (IHandle<NewCustomerCreated>));
        });

        //For(typeof (IHandle<>)).Use(typeof (NewCustomerCreated));
}

NewCustomerCreated is the event and I want to register all Handlers for this event ie ones using IHandle<NewCustomerCreated>

The following code is working but I am sure there it can be done by scanning :-

ObjectFactory.Initialize(x =>
    {                                                      
        x.For(typeof(IHandle<NewCustomerCreated>))
            .Add(new NewCustomerCreatedHandler());                                                                        
        x.For(typeof(IHandle<NewCustomerCreated>))
            .Add(new SendWelcomeEmailToNewCustomer());
    });

I am trying to use DomainEvent raiser from
http://blog.robustsoftware.co.uk/2009/08/better-domain-event-raiser.html

** I would appreciate if someone can edit the question to reflect what I am asking in a better way **

Thank you,

Mar

Edit 1: Adding Code from blog

 public interface IEventDispatcher
    {

        void Dispatch<TEvent>(TEvent eventToDispatch) where TEvent : IDomainEvent;

    }


    public static class DomainEventDispatcher
    {

        public static IEventDispatcher Dispatcher { get; set; }



        public static void Raise<TEvent>(TEvent eventToRaise) where TEvent : IDomainEvent
        {

            Dispatcher.Dispatch(eventToRaise);

        }

    }


    public class StructureMapEventDispatcher : IEventDispatcher
    {

        public void Dispatch<TEvent>(TEvent eventToDispatch) where TEvent : IDomainEvent
        {

            foreach (var handler in ObjectFactory.GetAllInstances<IHandle<TEvent>>())
            {

                handler.Handle(eventToDispatch);

            }

        }

From my test project I am calling registry class which will scan the assembly

  public void RegisterAllEventHandlers()
        {
            Scan(cfg =>
            {
                cfg.TheCallingAssembly();
                cfg.IncludeNamespace("Project1");
                //cfg.AddAllTypesOf(typeof(IHandle<NewCustomerCreated>));
                cfg.ConnectImplementationsToTypesClosing(typeof(IHandle<>));

            });

            // This initializes correctly 
            //ObjectFactory.Initialize(x =>
            //{
            //    x.For(typeof(IHandle<NewCustomerCreated>)).Add(new NewCustomerCreatedHandler());

            //}); 



          // Handler  returns 0 count 

          var handler =ObjectFactory.GetAllInstances<IHandle<NewCustomerCreated>>();





        }

and then

var eventDispatcher = new StructureMapEventDispatcher();
            DomainEventDispatcher.Dispatcher = eventDispatcher;
  • 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-17T19:49:03+00:00Added an answer on May 17, 2026 at 7:49 pm

    Try this:

    cfg.AddAllTypesOf(typeof (IHandle<>));
    

    Then your container will do the rest:

    var handler = container.GetInstance<IHandler<NewCustomerCreated>>(); 
    

    If you need more control take a look at this:
    https://stackoverflow.com/questions/516892/structuremap-auto-registration-for-generic-types-using-scan

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

Sidebar

Related Questions

I'm trying to get structuremap to build Fluent Nhibernate's SessionSource object for some of
New to Linux programming in general. I am trying to communicate with a kernel
I'm trying to use the MoqAutoMocker class that comes with StructureMap and I can't
I'm currently trying to implement StructureMap's AutoMocking functionality and I need help with getting
Has anyone used structuremap with the new DI features of asp.net mvc 3.0? If
I'm new to StructureMap and have some existing code that I'm working with that
Why is the IDependecyResolver trying to get an instance of IControllerFactory although I registered
New class is a subclass of the original object It needs to be php4
New to javascript/jquery and having a hard time with using this or $(this) to
New to xml. Looking for XPath to search a xml file with python ElementTree

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.