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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:55:59+00:00 2026-05-28T22:55:59+00:00

I’m trying to autowire up my application using Autofac. All is fine apart from

  • 0

I’m trying to autowire up my application using Autofac. All is fine apart from the fact I have an abstract generic type such as:

public abstract class Transformer<TModel>
{
  // Some abstract methods
}

With it implemented as:

public class EventTransformer : Transformer<Event>
{
  // implementation of methods
}

I’m autowiring up the application with:

builder.RegisterAssemblyTypes(typeof (MyAssemblyName).Assembly)
    .InstancePerLifetimeScope();

Autofac will then throw an error when resolving this type of class:

public class RandomClass<TModel>
{ 
  public RandomClass(Transformer<TModel> transformer() 
  {
     // Constructor code
  }
}

I get the error below (simplified). I can register the EventTransformer manually as Transformer < Event > and everything works fine, but I don’t want to have to register it manually, I should be able to do it automatically so I can simply create a new class and it’s straight into the application.

The requested service Transformer`1[[Event]]' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

I did try and use the method .AsImplementedInterfaces() when registering the classes but it didn’t seem to work.

So what should I be doing to accomplish this? Also for bonus points, I have no way of knowing what Autofac is registering and what it’s registering it as. Is there anyway of doing this?

  • 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-28T22:55:59+00:00Added an answer on May 28, 2026 at 10:55 pm

    You need to register the open generic types with the AsClosedTypesOf method during assembly scanning:

    builder.RegisterAssemblyTypes(typeof(MyAssemblyName).Assembly)
        .InstancePerLifetimeScope();
    builder.RegisterAssemblyTypes(typeof(MyAssemblyName).Assembly)
        .AsClosedTypesOf(typeof(Transformer<>))
        .InstancePerLifetimeScope();
    

    And you can get the registered components with:

    IContainer container = builder.Build();
    var registrations = container.ComponentRegistry.Registrations;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.