Demo entry 6742750



Submitted by anonymous on May 18, 2018 at 19:50
Language: C#. Code size: 941 Bytes.

// Create the builder with which components/services are registered.
    var builder = new ContainerBuilder();

    // Register types that expose interfaces...

    // Register instances of objects you create...
    var output = new StringWriter();

    // Register expressions that execute to create objects...
    builder.Register(c => new ConfigReader("mysection")).As<IConfigReader>();

    // Build the container to finalize registrations
    // and prepare for object resolution.
    var container = builder.Build();

    // Now you can resolve services using Autofac. For example,
    // this line will execute the lambda expression registered
    // to the IConfigReader service.
    using(var scope = container.BeginLifetimeScope())
      var reader = scope.Resolve<IConfigReader>();

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).