Skip to main content

We have changed the Dependency Injector in our Sitecore 9.1 solution to use Autofac, following this description: https://doc.sitecore.com/developers/90/sitecore-experience-management/en/dependency-injection.htmlthis description as as well as receiving a support .dll from Sitecore support.

We register our types using this configurator code:

public class SitecoreExtensionsConfigurator : IServicesConfigurator
    {
        public void Configure(IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient<ITrackerService, TrackerService>();
            serviceCollection.AddSingleton<IRenderingPropertiesRepository, RenderingPropertiesRepository>();
        }
    }

However, as far as I understand it, it just uses the Microsoft DI framework to register the types. What if I want to register my components using Autofac syntax, like:

public void Configure(IServiceCollection serviceCollection)
    {
        var builder = new ContainerBuilder();
        builder.RegisterType<TrackerService>()
            .As<ITrackerService>();
    }

However, that makes my site fail, with an exception, stating that ITrackerService is not registeredITrackerService is not registered.

We have changed the Dependency Injector in our Sitecore 9.1 solution to use Autofac, following this description: https://doc.sitecore.com/developers/90/sitecore-experience-management/en/dependency-injection.html as well as receiving a support .dll from Sitecore support.

We register our types using this configurator code:

public class SitecoreExtensionsConfigurator : IServicesConfigurator
    {
        public void Configure(IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient<ITrackerService, TrackerService>();
            serviceCollection.AddSingleton<IRenderingPropertiesRepository, RenderingPropertiesRepository>();
        }
    }

However, as far as I understand it, it just uses the Microsoft DI framework to register the types. What if I want to register my components using Autofac syntax, like:

public void Configure(IServiceCollection serviceCollection)
    {
        var builder = new ContainerBuilder();
        builder.RegisterType<TrackerService>()
            .As<ITrackerService>();
    }

However, that makes my site fail, with an exception, stating that ITrackerService is not registered.

We have changed the Dependency Injector in our Sitecore 9.1 solution to use Autofac, following this description as well as receiving a support .dll from Sitecore support.

We register our types using this configurator code:

public class SitecoreExtensionsConfigurator : IServicesConfigurator
{
    public void Configure(IServiceCollection serviceCollection)
    {
        serviceCollection.AddTransient<ITrackerService, TrackerService>();
        serviceCollection.AddSingleton<IRenderingPropertiesRepository, RenderingPropertiesRepository>();
    }
}

However, as far as I understand it, it just uses the Microsoft DI framework to register the types. What if I want to register my components using Autofac syntax, like:

public void Configure(IServiceCollection serviceCollection)
{
    var builder = new ContainerBuilder();
    builder.RegisterType<TrackerService>()
        .As<ITrackerService>();
}

However, that makes my site fail, with an exception, stating that ITrackerService is not registered.

added 77 characters in body
Source Link
Hos
  • 884
  • 10
  • 21

We have changed the Dependency Injector in our Sitecore 9.1 solution to use Autofac, following this description: https://doc.sitecore.com/developers/90/sitecore-experience-management/en/dependency-injection.html as well as receiving a support .dll from Sitecore support.

We register our types using this configurator code:

public class SitecoreExtensionsConfigurator : IServicesConfigurator
    {
        public void Configure(IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient<ITrackerService, TrackerService>();
            serviceCollection.AddSingleton<IRenderingPropertiesRepository, RenderingPropertiesRepository>();
        }
    }

However, as far as I understand it, it just uses the Microsoft DI framework to register the types. What if I want to register my components using Autofac syntax, like:

public void Configure(IServiceCollection serviceCollection)
    {
        var builder = new ContainerBuilder();
        builder.RegisterType<TrackerService>()
            .As<ITrackerService>();
    .WithParameter(new TypedParameter(typeof(string), "sectionName"));}

How will I add that registration to the serviceCollection? However, that makes my site fail, with an exception, stating that ITrackerService is not registered.

We have changed the Dependency Injector in our Sitecore 9.1 solution to use Autofac, following this description: https://doc.sitecore.com/developers/90/sitecore-experience-management/en/dependency-injection.html as well as receiving a support .dll from Sitecore support.

We register our types using this configurator code:

public class SitecoreExtensionsConfigurator : IServicesConfigurator
    {
        public void Configure(IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient<ITrackerService, TrackerService>();
            serviceCollection.AddSingleton<IRenderingPropertiesRepository, RenderingPropertiesRepository>();
        }
    }

However, as far as I understand it, it just uses the Microsoft DI framework to register the types. What if I want to register my components using Autofac syntax, like:

var builder = new ContainerBuilder();
builder.RegisterType<TrackerService>()
.As<ITrackerService>();
    .WithParameter(new TypedParameter(typeof(string), "sectionName"));

How will I add that registration to the serviceCollection?

We have changed the Dependency Injector in our Sitecore 9.1 solution to use Autofac, following this description: https://doc.sitecore.com/developers/90/sitecore-experience-management/en/dependency-injection.html as well as receiving a support .dll from Sitecore support.

We register our types using this configurator code:

public class SitecoreExtensionsConfigurator : IServicesConfigurator
    {
        public void Configure(IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient<ITrackerService, TrackerService>();
            serviceCollection.AddSingleton<IRenderingPropertiesRepository, RenderingPropertiesRepository>();
        }
    }

However, as far as I understand it, it just uses the Microsoft DI framework to register the types. What if I want to register my components using Autofac syntax, like:

public void Configure(IServiceCollection serviceCollection)
    {
        var builder = new ContainerBuilder();
        builder.RegisterType<TrackerService>()
            .As<ITrackerService>();
    }

However, that makes my site fail, with an exception, stating that ITrackerService is not registered.

Source Link
Hos
  • 884
  • 10
  • 21

How to make use of Autofac in IServicesConfigurator

We have changed the Dependency Injector in our Sitecore 9.1 solution to use Autofac, following this description: https://doc.sitecore.com/developers/90/sitecore-experience-management/en/dependency-injection.html as well as receiving a support .dll from Sitecore support.

We register our types using this configurator code:

public class SitecoreExtensionsConfigurator : IServicesConfigurator
    {
        public void Configure(IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient<ITrackerService, TrackerService>();
            serviceCollection.AddSingleton<IRenderingPropertiesRepository, RenderingPropertiesRepository>();
        }
    }

However, as far as I understand it, it just uses the Microsoft DI framework to register the types. What if I want to register my components using Autofac syntax, like:

var builder = new ContainerBuilder();
builder.RegisterType<TrackerService>()
.As<ITrackerService>();
    .WithParameter(new TypedParameter(typeof(string), "sectionName"));

How will I add that registration to the serviceCollection?