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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:53:45+00:00 2026-05-30T18:53:45+00:00

How do I register a closed type so that instances of the generic are

  • 0

How do I register a closed type so that instances of the generic are created using HybridHttpOrThreadLocalScoped lifecycle?

My classes:

public interface IBaseService
{
}

public interface IAccountService
{
    void Save(Account entry);
    Account GetById(string id);
    List<Account> GetList();
    void Delete(string id);
    bool Exists(string id);
}

public interface IClientService
{
    void Save(Client entry);
    Client GetById(string id);
    List<Client> GetList();
    void Delete(string id);
    bool Exists(string id);
}

public class AccountService : IBaseService, IAccountService
{
    Some code for managing accounts
}

public class ClientService : IBaseService, IClientService
{
    Some code for managing clients
}

Dependency resolver:

    public StructureMapContainer(IContainer container)
    {
        _container = container;

        _container.Configure(x => x.Scan(y =>
        {
            y.AssembliesFromApplicationBaseDirectory();
            y.WithDefaultConventions();
            y.LookForRegistries();
            y.ConnectImplementationsToTypesClosing(typeof(IService<>))
                 .OnAddedPluginTypes(t => t.HybridHttpOrThreadLocalScoped());
        }));

    }

What’s the syntax in the resolver for automatically creating instances of IBaseService? Using ConnectImplementationsToTypesClosing only works for open generics. Do I even need to use the resolver? Is there a better way to register the types?

For now, this is how I amhandling registering them:

container.Configure(x =>
        {
            x.For<IClientService>()
                .HybridHttpOrThreadLocalScoped()
                .Use(new ClientService());

            x.For<IEmailAddressService>()
                .HybridHttpOrThreadLocalScoped()
                .Use(new EmailAddressService());

            x.For<IAccountService>()
                .HybridHttpOrThreadLocalScoped()
                .Use(new AccountService());
        });
  • 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-30T18:53:47+00:00Added an answer on May 30, 2026 at 6:53 pm

    Something like:

        Scan(y =>
        {
            y.AssemblyContainingType<IService>();
            y.Assembly(Assembly.GetExecutingAssembly().FullName);
            y.With(new ServiceScanner());
        });
    

    Then you need the Customscanner:

    /// <summary>
    /// Custom scanner to create Service types based on custom convention
    /// In this case any type that implements IService and follows the 
    /// naming convention of "Name"Service.
    /// </summary>
    public class ServiceScanner : IRegistrationConvention
    {
        public void Process(Type type, StructureMap.Configuration.DSL.Registry registry)
        {
            if (type.BaseType == null) return;
    
            if (type.GetInterface(typeof(IService).Name) != null)
            {
                var name = type.Name;
                var newtype = type.GetInterface(string.Format("I{0}", name));
    
                registry
                   .For<IService>()
                   .AddInstances(y => y.Instance(new ConfiguredInstance(type).Named(name)))
                   .HybridHttpOrThreadLocalScoped();
    
                registry.For(newtype)
                    .HybridHttpOrThreadLocalScoped().Use(c => c.GetInstance<IService>(name));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using register_shutdown_function I can register code to execute at the end of a PHP
how can I register my application so that when I receive a sms my
I am trying to create a SIMPLE plugin, no interface is necessary, that will
I have a childwindow with an associated VM that gets created each time I
Is possible create (register) a new class in runtime using delphi. I have a
int* Register = 0x00FF0000; // Address of micro-seconds timer while(*Register != 0); Should I
I register the following function //EDIT: updated $("#id").on("change", function() { alert('xxx'); }); In my
containerBuilder .Register<IGraphClient>(context => { var graphClient = new GraphClient(new Uri(http://localhost:9999/db/data)); graphClient.Connect(); // Particularly this
I register a NSNotification in viewDidLoad method. Should I unregister it both in viewDidUnload
Why are register-based virtual machines better than stack-based ones? Specifically, in the Parrot VM's

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.