-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Hello,
We are going through a very large migration from Unity container to PureDI. Our goal is to improve our startup performance.
Unfortunately due to environmental factors I have no direct control of, a very large portion of the codebase does not really do dependency injection but is using the ServiceLocator pattern as a dependency resolution technic. To make things work I created the following wrapper:
using CommonServiceLocator;
using OfficeSuite.DependencyInjection;
using System;
using System.Collections.Generic;
namespace WordApp.DIConfig
{
internal class PureDiServiceLocator : IServiceLocator, OfficeSuite.DependencyInjection.IServiceProvider
{
private readonly Composition composition;
public PureDiServiceLocator(Composition composition)
{
this.composition = composition;
}
public IEnumerable<object> GetAllInstances(Type serviceType)
{
throw new NotImplementedException();
}
public IEnumerable<TService> GetAllInstances<TService>()
{
throw new NotImplementedException();
}
public IEnumerable<T> GetAllServices<T>(params IObjectOverride[] objectOverrides)
{
throw new NotImplementedException();
}
public object GetInstance(Type serviceType)
{
return composition.Resolve(serviceType);
}
public object GetInstance(Type serviceType, string key)
{
return composition.Resolve(serviceType, key);
}
public TService GetInstance<TService>()
{
return (TService)composition.Resolve(typeof(TService));
}
public TService GetInstance<TService>(string key)
{
return (TService)composition.Resolve(typeof(TService), key);
}
public object GetService(Type serviceType)
{
return composition.Resolve(serviceType);
}
public object GetService(Type serviceType, string key, params IObjectOverride[] objectOverrides)
{
throw new NotImplementedException();
}
public void Teardown()
{
}
}
}After migrating the first app, I quickly measured the startup time and to my surprise it was actually slower than before (Release build). I'm wondering if the natural cause of this could be that 99% of the registrations have .Root() on them to make things work with that damn locator.
We could of course extend the scope of our task and build up the entire dependency tree at once instead of resolving them like this. But this scope creep has to be justified. I would like to know if we're taking a big performance hit from having so many (99% of our 1300 registrations) end with .Root<T>(). The generated Composition.cs file has about 30k lines of code.