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

The Archive Base Latest Questions

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

Situation: We have several classes, which are registred as interface. Also this classes are

  • 0

Situation: We have several classes, which are registred as interface. Also this classes are marked with custom attribute. We want to go throught all registered components in the end of App containew building and create new registrations based on ot. For example,

[CustomAttribute]
public class Foo: IFoo
{
    [NewCustomActionAttribute("Show me your power!")]
    public void Do() {}
}

So we are doing this – builder.Register<Foo>.As<IFoo>();
And a lot of the similar classes into another plugins. After all plugins beeing registered, we want to add new class to builder, e.g. ICustomAction with some metadata like caption and module, and load it later based on this registration.
What is the best way to do that?

UPDATE:

var types = // get all registered types
foreach (var typeToProceed in types.Where(_ => _.GetCustomAttributes(typeof(CustomAttribute), false).FirstOrDefault != null)
{
   var customMethodAttributes = // Get NewCustomActionAttributes from this type
   for each customAttr
       builder.Register(new CustomClass(customAttr.Caption, dynamic delegate to associated method);
   end for aech
}

I do not want to do it in the vase bootstrap, because there may be a lot of another attributes. The best way is to add (only once) new classes when this item (Toolbar) is requsted first.

  • 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-15T03:14:12+00:00Added an answer on June 15, 2026 at 3:14 am

    I would create a new extension method RegisterCustomClasses that handles the registration:

    public static class AutofacExtensions
    {
        public void RegisterCustomClasses<T>(this ContainerBuilder builder)
        {
            var methods = typeof(T).GetMethods();
            var attributes = methods.Select(x => new
                                            {
                                                Method = x,
                                                Attribute = GetAttribute(x)
                                            })
                                    .Where(x => x.Attribute != null);
    
            foreach(var data in attributeData)
                builder.RegisterInstance(new CustomClass(data.Attribute.Caption, 
                                                         data.Method));
        }
    
        private static NewCustomActionAttribute GetAttribute(MethodInfo method)
        {
            return method.GetCustomAttributes(typeof(NewCustomActionAttribute))
                         .OfType<NewCustomActionAttribute>()
                         .FirstOrDefault()
        }
    }
    

    Usage:

    builder.Register<Foo>.As<IFoo>();
    builder.RegisterCustomClasses<Foo>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So the situation is like this: I have several links, each with one hidden
My situation: I have several components, which sometimes have changes to them, and are
I'm dealing with this situation : I have a color animation script which targets
I took over an ASP.NET application and have found this throughout several classes in
I have a situation where I have several VB.NET Modules in the same Logical-Module
I have a situation where I need to concatenate several string to form an
I have a problem with the following situation: several commits are pushed to a
I have had several situations when i would like to do that. This could
I have following situation - Have a MongoService class, which reads host, port, database
Situation: I have an index page which loads pages into it with ajax as

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.