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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:44:53+00:00 2026-05-15T09:44:53+00:00

This is a (to me) pretty weird problem, because it was already running perfectly

  • 0

This is a (to me) pretty weird problem, because it was already running perfectly but went completely south after some unrelated changes.

I’ve got a Repository which imports in its constructor a list of IExtensions via Autofacs MEF integration. One of these extensions contains a backreference to the Repository as Lazy(Of IRepository) (lazy because of the circular reference that would occur).

But as soon as I try to use the repository, Autofac throws a ComponentNotRegisteredException with the message "The requested service ‘ContractName=Assembly.IRepository()’ has not been registered."

That is, however, not really correct, because when I break right after the container-build and explore the list of services, it’s there – Exported() and with the correct ContractName.

I’d appreciate any help on this…
Michael

[Edit] Here’s a thinned-out version of the code:

Repository

Public Class DocumentRepository
    Implements IDocumentRepository

    Private _extensions As IEnumerable(Of IRepositoryExtension)
    
    Public Sub New(ByVal extensions As IEnumerable(Of IRepositoryExtension))
        _extensions = extensions
    End Sub

    Public Sub AddDocument(ByVal document As Contracts.IDocument) Implements Contracts.IDocumentRepository.AddDocument
        For Each extension In _extensions
            extension.OnAdded(document.Id)
        Next
    End Sub
End Class

Plugin

<Export(GetType(IRepositoryExtension))>
<PartCreationPolicy(ComponentModel.Composition.CreationPolicy.Shared)>
Public Class PdfGenerator
    Implements IRepositoryExtension

    Private _repositoryFactory As Lazy(Of IDocumentRepository)
    
    Public Sub New(ByVal repositoryFactory As Lazy(Of IDocumentRepository))
        _repositoryFactory = repositoryFactory
    End Sub

    Public Sub CreatePdf(ByVal id As Guid) Implements Contracts.IRepositoryExtension.OnAdded
        Dim document = _repositoryFactory.Value.GetDocumentById(id)
    End Sub
End Class

Bootstrapper

Public Class EditorApplication
    Inherits System.Web.HttpApplication

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        Dim builder As New ContainerBuilder()
        
        Dim catalog1 As New TypeCatalog(GetType(DataRepositoryScheme))
        Dim catalog2 As New DirectoryCatalog(HttpContext.Current.Server.MapPath("/Plugins"))
        builder.RegisterComposablePartCatalog(New AggregateCatalog(catalog1, catalog2))
        
        builder.RegisterType(Of DocumentRepository).As(Of IDocumentRepository).SingleInstance().Exported(Function(x) x.As(Of IDocumentRepository)())
        
        AutofacServiceHostFactory.Container = builder.Build()
    End Sub
End Class
  • 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-15T09:44:54+00:00Added an answer on May 15, 2026 at 9:44 am

    Ah immediately after I posted that last comment I think I figured it out:

    The requested service 'ContractName=ConsoleApplication7.IDocumentRepository()'
    has not been registered.
    

    Note that there is a pair of parentheses after the contract name – this is because the contract is a function, i.e., this message was produced by the following constructor, which is slightly different from the one in your sample:

    Public Sub New(ByVal repositoryFactory As Func(Of IDocumentRepository))
        _repositoryFactory = repositoryFactory
    End Sub
    

    Note the ‘Func’ in there. MEF, unlike Autofac, does not regard Func as a special type and so will not translate this into the same contract as for Lazy.

    If you want to provide a Func to a MEF component, you need to export it as a Func from Autofac. This is a bit tricky:

    builder.RegisterType(Of DocumentRepository).As(Of IDocumentRepository)
    
    builder.Register(Function(c) c.Resolve(Of Func(Of IDocumentRepository))) _
        .As(New UniqueService()) _
        .Exported(Function(x) x.As(Of Func(Of IDocumentRepository))
    

    You may need to play with the syntax a bit, my VB.NET is fairly shaky.

    My guess is that there are stale binaries in your /Extensions directory that are interfering with debugging this.

    Hope this is on the mark!

    Nick

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

Sidebar

Related Questions

I'm having some weird issues with Xcode, and this is pretty much impossible to
I’m sorry if the title isn’t clear, but this is a weird problem. I
This is pretty weird. I have my Profiler open and it obviously shows that
This is pretty trivial, but I noticed on SO that instead of an offset
So this seems pretty basic but I can't get it to work. I have
I thought this was pretty straight forward but I don't get the same results
This is a pretty-much theoretical question, but.. How much of an operating system could
I'm really confused - but really it's pretty wierd because I know two programming
This pretty much has me defeated. On XP and earlier versions of Windows you
This is pretty simple, I come from a swing/awt background. I'm just wondering what

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.