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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:38:42+00:00 2026-05-22T15:38:42+00:00

I am trying to use StructureMap to register some types that implement a generic

  • 0

I am trying to use StructureMap to register some types that implement a generic interface and are instantiated via a factory.

My code:

    public interface IManagerBase<T, TKey> : IDisposable
    {
        // Get Methods
        T GetById(TKey Id);
    }

    public partial interface IServerHostManager : IManagerBase<ServerHost, int>
    {
        // ServerHost Specific Get Methods
    }    

    partial class ServerHostManager : ManagerBase<ServerHost, int>, IServerHostManager
    {
        // Implementation
    }

    public class ManagerFactory : IManagerFactory
    {
        public IServerHostManager GetServerHostManager()
        {
            return new ServerHostManager();
        }
    }

This works fine:

 For<IServerHostManager>().HybridHttpOrThreadLocalScoped()
.Use(new ManagerFactory().GetServerHostManager());

My factory is called and a new instance of IServerHostManager is returned.

Is there any way I can scan for all generic types and have them instantiated via my factory?

This does not work due to ServerHostManager being an internal class:

        Scan(x =>
        {
            x.AssemblyContainingType(typeof(IManagerBase<,>));
            x.AddAllTypesOf(typeof(IManagerBase<,>));
            x.ConnectImplementationsToTypesClosing(typeof(IManagerBase<,>))
                .OnAddedPluginTypes(t => t.HybridHttpOrThreadLocalScoped());
        });

What scan command can I use to tell SM to call my factory?

Thank you,

Rick

Followup added on 5/4:

Sorry for the delay in following up.

I’ve got a bunch of manager objects (> 75) that CodeSmith’s nHibernate template has created. They are normally accessed via a factory object. Instead, I’d like to scan for them have them all registered automatically.

This is how I register the objects now:

For<IActivityLogManager>().HybridHttpOrThreadLocalScoped() 
.Use(new ManagerFactory().GetActivityLogManager()); 

For<IAspnetUserManager>().HybridHttpOrThreadLocalScoped() 
.Use(new ManagerFactory().GetAspnetUserManager()); 

Here are the objects

public interface IManagerBase<T, TKey> : IDisposable
{
    // Get Methods 
    T GetById(TKey Id);
}

public partial interface IActivityLogManager : IManagerBase<BusinessObjects.ActivityLog, int>
{
    // Get Methods
    IList<ActivityLog> GetByActivityTypeId(System.Int32 activityType);
}

public partial class ActivityLogManager : ManagerBase<BusinessObjects.ActivityLog, int>, IActivityLogManager
{
    public IList<ActivityLog> GetByActivityTypeId(System.Int32 activityType)
    {
        // Code to fetch objects
    }    
}

public partial interface IAspnetUserManager : IManagerBase<BusinessObjects.AspnetUser, System.Guid>
{
    // Get Methods
    IList<ActivityLog> GetByActivityTypeId(System.Int32 activityType);
}

public partial class AspnetUserManager : ManagerBase<BusinessObjects.AspnetUser, System.Guid>, IAspnetUserManager
{
    public IList<AspnetUser> GetAll()
    {
        // Code to fetch objects
    }    
}

My Scan code:

Scan(x => 
    { 
        x.AssemblyContainingType(typeof(IManagerBase<,>)); 
        x.AddAllTypesOf(typeof(IManagerBase<,>)); 
        x.ConnectImplementationsToTypesClosing(typeof(IManagerBase<,>)) 
            .OnAddedPluginTypes(t => t.HybridHttpOrThreadLocalScoped());     
    });

The Scan code above does not find any objects in the assembly.

I hope this clarifies my scenario.

Thank you,

Rick

  • 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-22T15:38:43+00:00Added an answer on May 22, 2026 at 3:38 pm

    This issue can be solved by making the assembly a friend:

    [assembly: InternalsVisibleTo("AssemblyB")]
    

    http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx

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

Sidebar

Related Questions

I'm trying to use the MoqAutoMocker class that comes with StructureMap and I can't
I am new to structuremap. I am trying to get Structuremap to auto-register public
I'm trying to use StructureMap 2.6.1 to register all my repositories at once using
I'm trying to use svnmerge.py to merge some files. Under the hood it uses
I'm trying to use SQLBindParameter to prepare my driver for input via SQLPutData .
I'm trying to use jQuery to format code blocks, specifically to add a <pre>
I'm trying to use the Optiflag package in my Ruby code and whenever I
I am using wcf 4 and trying to use some Ioc container to resolve
I'm trying to get structuremap to build Fluent Nhibernate's SessionSource object for some of
Trying to use Linq with some Entity objects to do a crafty query here.

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.