JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
572 stars 119 forks source link

ServiceRegistry doesn't support arguments #129

Closed silkfire closed 5 years ago

silkfire commented 5 years ago

What's the convention of supplying arguments to the custom ServiceRegistry classes? As of now, it doesn't seem possible. It's as if Lamar assumes that all needed data can be retrieved from within the registry class.

ServiceRegistry:
      public void IncludeRegistry<T>() where T : ServiceRegistry, new();

My service registry looks like this:

public class JsonStorageEngineRegistry : ServiceRegistry
{
        // Constructor needs these parameters in order to resolve services

        public JsonStorageEngineRegistry(IConfigurationRoot configuration, string contentRootPath)
        {
             ....
        }
}
jeremydmiller commented 5 years ago

Someone else hit this. I'm perfectly willing to take a pull request for an overload of IncludeRegistry() that just takes a ServiceRegistry object.

danspam commented 5 years ago

You can always just use AddRange(new RegistryWithArgs(myArg));

silkfire commented 5 years ago

@jereremydmiller Since I wrote the post I've moved to Grace (https://github.com/ipjohnson/Grace) instead, as it is easier to use and much more performant.

jeremydmiller commented 5 years ago

@silkfire Dude, after as huge a PITA as you've been on the SM and Lamar issue lists, you leave a comment like that? I'm very content for you to be their problem.

silkfire commented 5 years ago

@jereremydmiller Well it's very unfortunate that Lamar suffers from the same performance issues that SM does. My apps initialize much faster since I've switched to Grace.

jeremydmiller commented 5 years ago

Again, you were a huge pain to me over the years. I also pushed the changes today that made a drastic difference in that regard. I'm not going to miss your weird, time consuming generics questions. You are exactly the kind of person that makes being an OSS author miserable sometimes.

silkfire commented 5 years ago

You're making such a big deal out of this. I can't possibly have bothered you that much that you must've remembered me. There are tonnes of other people reporting issues on your projects. PS. Oh btw Lamar is such a lame name for the IoC library. Goodbye.

cocowalla commented 4 years ago

An extension method to work around this:

public static class LamarExtensions
{
    public static void IncludeRegistry<T>(this ServiceRegistry parentRegistry, T includeRegistry) where T : ServiceRegistry
    {
        parentRegistry.AddRange(includeRegistry);
    }
}