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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:03:21+00:00 2026-06-02T16:03:21+00:00

var servers = new List<IChecker> { //Server1 new DatabaseSystem { ServerName = ANTIVIRUS },

  • 0
      var servers = new List<IChecker> {
      //Server1
      new DatabaseSystem { ServerName = "ANTIVIRUS" },
      new DatabaseSizes  { ServerName = "ANTIVIRUS"},
      new DiskBackup { ServerName = "ANTIVIRUS"},
      new SqlServerEventLog { ServerName="ANTIVIRUS"},
      new DiskSystem { ServerName="ANTIVIRUS"}, 
      //Server1
      new DatabaseSystem { ServerName="SEJKG-S-DB01" },
      new DatabaseSizes  { ServerName = "SEJKG-S-DB01"},
      new DiskBackup { ServerName = "SEJKG-S-DB01"},
      new SqlServerEventLog { ServerName="SEJKG-S-DB01"},
      new DiskSystem { ServerName="SEJKG-S-DB01"},
  };

  var builder = new ContainerBuilder();            
  builder.RegisterInstance(notifiers).As<IList<INotifier>>();     
  builder.RegisterInstance(servers).As<IList<IChecker>>();
  builder.Register(c => new ServerChecker(c.Resolve<IList<IChecker>>(),  c.Resolve<IList<INotifier>>()));
  return builder.Build();

I have a problem with how I should register my “where server = new List {..} ‘to the Container Builder. My List of iChecker passed as a parameter to a ServerChecker. So much have I been able to solve, but not the list itself but I must have outside. The usual list of servers is much greater.

  • 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-02T16:03:22+00:00Added an answer on June 2, 2026 at 4:03 pm

    Autofac has implicit collection support such that you can register multiple individual items and when you resolve an IEnumerable of those items you will get all of the registrations:

    var builder = new ContainerBuilder();
    builder.RegisterType<FirstType>().As<IDependency>();
    builder.RegisterType<SecondType>().As<IDependency>();
    builder.RegisterType<ThirdType>().As<IDependency>();
    var container = builder.Build();
    using(var scope = container.BeginLifetimeScope())
    {
      var allDependencies = scope.Resolve<IEnumerable<IDependency>>();
      // allDependencies will contain all three of the registered types.
    }
    

    This would allow you to greatly simplify the registrations since you wouldn’t have to actually build the list ahead of time – you could just register each of your “IChecker” or “INotifier” instances directly and resolve the IEnumerable of them.

    If you have the ability to change your “ServerChecker” constructor to take IEnumerable rather than IList, then you’re done – you don’t need to do the c.Resolve() thing anymore. That’s possibly a better design anyway because IList implies the collection can be modified later, which is probably not what you want. (It may be that ServerChecker copies the contents of the IEnumerable into its own list so you could modify a local copy, but you wouldn’t want folks to think they can or should modify the contents of the central dependency like that.)

    If it has to be IList, you could add another registration that creates the list on the fly:

    builder
      .Register(c => new List<IDependency>(c.Resolve<IEnumerable<IDependency>>()))
      .As<IList<IDependency>>();
    

    That way you still can avoid doing the c.Resolve<…>() call in the resolution for the “ServerChecker” – Autofac will suddenly know about how to create the specific type of list.

    If you really want to get fancy with it, you could add a custom Autofac RegistrationSource such that if anyone tries to resolve IList Autofac would automatically do the resolve of the IEnumerable and create a list… but that’s a little more than you probably need.

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

Sidebar

Related Questions

reader = server.ExecuteReader(CommandType.Text, getPermissionlistQuery, param); var results = new List<string>(); while (reader.Read()) { results.Add(reader[permissionName].ToString());
List<NastavaIzvjestaj> nastava_izvjestaj = new List<NastavaIzvjestaj>(); var data_context = new DataEvidencijaDataContext(); int pomSum = 0;
Trying to create COM -object on server. code is: var myGuid = new Guid(530A1815-820C-11D3-BBB7-008048DE406A);
I'd like to bind a List of Dictionary to a GridView. var liste =
I have a list of websites and a list of proxy servers. I have
The following Server-Side code works: [OperationContract] public IEnumerable<object> GetBooks() { var people = new
public static void ListFolders() { HomeFolderListing = new List<string>(); ReportingServiceSoapClient rs = new ReportingServiceSoapClient();
Trying to extract list of Queue Elements into a new list of Queue objects.
i am using the following code to send request to the server var url='getDNormalForm.action';
I have two backbone models, loaded from server: var Model = Backbone.Model.extend({}); var SubModel

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.