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

  • Home
  • SEARCH
  • 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 6782685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:46:22+00:00 2026-05-26T16:46:22+00:00

I am using the Registry DSL example to configure structuremap. But doing this makes

  • 0

I am using the Registry DSL example to configure structuremap. But doing this makes all of my registered types available in all layers of my application where I add a refernce to structure map. I dont want my business layer to know anything about my data access layer and vice versa. How do I get structuremap to only register specific types for each of my layers?

Here is the code in my global.asax file:

ObjectFactory.Initialize(x =>
{
  x.AddRegistry<RegistryIOC>();
});

And here is my RegistryIOC class:

public class RegistryIOC : SMRegistry
{

    public RegistryIOC() 
    {
        For<IProfileService>.Use<ProfileService>();
        For<IProctorService>().Use<ProctorService>();

        //Business Logic Objects
        For<IQual>().Use<Qual>();
        For<ITest>().Use<Test>();
        For<IBoldface>().Use<Boldface>();
        For<ITrainingPlan>().Use<TrainingPlan>();
        For<IUnit>().Use<Unit>();

        //Data Transfer Objects
        For<IGenericDTO>().Use<GenericDTO>();
        For<IProfileDTO>().Use<ProfileDTO>();
        For<IQualDTO>().Use<QualDTO>();
        For<IPermissionDTO>().Use<PermissionDTO>();

        //Repository Objects
        For<IProctorRepository>().Use<ProctorRepository>();
        For<IQualsRepository>().Use<QualsRepository>();
        For<ITestRepository>().Use<TestRepository>();
        For<IUnitRepository>().Use<UnitRepository>();
        For<IUserRepository>().Use<UserRepository>();
    }

}

Thanks for the help.

  • 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-26T16:46:23+00:00Added an answer on May 26, 2026 at 4:46 pm

    I am using reflection to accomplish this (and other) tasks. Let me show how that works.

    The first thing to do is to define an interface that allows us to identify classes that perform initialization tasks:

    public interface IConfigurationTask
    {
        void Configure();
    }
    

    Next, create one or more classes that implement this interface. These classes will be spread across all of your projects, which is another way of saying that you can put them “where they belong”.

    public class RepositoryInitializer : IConfigurationTask
    {
        public void Configure()
        {
            // code that does relevant initialization goes here
        }
    }
    

    The last piece of the puzzle is to find classes that implement the IConfigurationTask interface, create an instance of them and execute the Configure method. This is the purpose of the ConfigurationTaskRunner:

    public static class ConfigurationTaskRunner
    {
        public static void Execute( params string[] assemblyNames )
        {
            var assemblies = assemblyNames.Select( Assembly.Load ).Distinct().ToList();
            Execute( assemblies );
        }
    
        public static void Execute( IEnumerable<Assembly> assemblies )
        {
            var tasks = new List<IConfigurationTask>();
            assemblies.ForEach( a => tasks.AddRange( a.CreateInstances<IConfigurationTask>() ) );
    
            tasks.ForEach( t => t.Configure() );
        }
    }
    

    The code shown here uses a custom extension to iterate over all items in a list and execute an action for every item (the ForEach method). I am also using a reflection library to make the task of locating and instantiating the instances a one-liner (the CreateInstances method), but you could achieve the same using just plain reflection (as shown in the code below).

    public static IList<T> CreateInstances<T>( this Assembly assembly )
    {
         var query = from type in assembly.GetTypes().Where( t => typeof(T).IsAssignableFrom( t ) && typeof(T) != t ) 
                     where type.IsClass && ! type.IsAbstract && type.GetConstructor( Type.EmptyTypes ) != null 
                     select (T) Activator.CreateInstance( type );
         return query.ToList();
    }    
    

    The final piece of the puzzle is to trigger the execution of the ConfigurationTaskRunner. For example, in a web application this would go into Application_Start in Global.asax:

    // pass in the names of the assemblies we want to scan, hardcoded here as an example 
    ConfigurationTaskRunner.Execute( "Foo.dll", "Foo.Domain.dll" );
    

    I’ve also found it useful with a derived IPrioritizedConfigurationTask (that adds a Priority property) to allow proper ordering of the tasks before you execute them. This is not shown in the example code above, but is fairly trivial to add.

    Hope this helps!

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

Sidebar

Related Questions

How to create a windows registry watcher application using .Net, I want this application
I get a null back from this attempt to access the Windows Registry: using
I tried using Zend_Registry but it doesn't output anything then I tried this in
Example using Namespace in PHP... use \MyLibrary\Registry; use \MyLibrary\User; use \MyLibrary\Request; namespace MyLibrary\Base {
I know that we shouldn't being using the registry to store Application Data anymore,
Hai , How to set Key and Value in the client registry using javascript.
I want to modify the registry of window OS using c. kindly guide me
I am trying to create an offline registry in memory using the offreg.dll provided
(I'm on WM 6.5) I started using ::RegistryNotifyCallback when monitoring parts of the registry,
string registryKey = @SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall; using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryKey)) { (from a in key.GetSubKeyNames()

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.