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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:33:43+00:00 2026-05-31T21:33:43+00:00

containerBuilder .Register<IGraphClient>(context => { var graphClient = new GraphClient(new Uri(http://localhost:9999/db/data)); graphClient.Connect(); // Particularly this

  • 0
containerBuilder
    .Register<IGraphClient>(context =>
    {
        var graphClient = new GraphClient(new Uri("http://localhost:9999/db/data"));
        graphClient.Connect(); // Particularly this line
        return graphClient;
    })
    .SingleInstance();

While I can figure out how to register interfaces to concrete classes, this particular class needs to be a single instance (I’m pretty sure this is LifeStyle.Singleton) and also call the graphClient.Connect() method. That’s the main part I’m stuck on.

Based on JeffN825’s answer I did this:

container.Register(
                Component.For(
                    typeof (IGraphClient))
                    .ImplementedBy(typeof (GraphClient))
                    .LifeStyle.Singleton.UsingFactoryMethod(() =>
                                                                {
                                                                    var graphClient = new GraphClient(new Uri("http://localhost:7474/db/data"));
                                                                    graphClient.Connect();
                                                                    return graphClient;
                                                                }));
  • 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-31T21:33:44+00:00Added an answer on May 31, 2026 at 9:33 pm

    You can use the ComponentRegistration<T>.UsingFactoryMethod<T> method which takes a delegate (Func) if you want to control the instance creation yourself (which would also give you the chance to call Connect).

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

Sidebar

Related Questions

So lets say i have this code var builder = new ContainerBuilder(); builder.RegisterInstance(new MyType());
I have registered a component like this in my Global.asax.cs: ContainerBuilder builder = new
I am testing out Autofac container with these below: var builder = new ContainerBuilder();
How would I convert the existing C# code _containerBuilder = new ContainerBuilder(); _containerBuilder.RegisterGeneric(typeof(CommandObserver<>)).As(typeof(ICommandObserver<>)); _containerBuilder.RegisterGeneric(typeof(PropertyProvider<>)).As(typeof(IPropertyProvider<>));
I need to register my Autofac container with specific interface, for this case I
Is it possible to register a service at run-time, meaning after the ContainerBuilder has
Using AutoFac 2.3.2, I am trying to do the following: var builder = new
I have an application which might needs to connect to multiple databases. But each
What is the NInject equivalent of the following code that uses Autofac: var builder
I notice the latest alpha of SolrNet supports Autofac integration. This wiki page discusses

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.