Search code examples
c#dependency-injectioninversion-of-controlioc-containerlight-inject

why Light Inject's source code all in one .cs file


like this https://github.com/seesharper/LightInject/blob/master/LightInject/LightInject.cs

It's hard to reading, is there any deep meaning?


Solution

  • Being the author of LightInject, I feel I should comment on this :)

    Say that you are a library developer and want to be able to utilize an IoC framework internally without taking a dependency on a third party assembly. By using the source version of LightInject, this can be done quite easily and you can still ship your library as a single assembly.

    Many framework developers choose not to use an IoC framework just because they don't want that extra dependency.

    The alternative to this would be to use tools like ILMerge that is capable of merging two or more assemblies into a single assembly.

    This is a far more advanced option and would also require an extra build step that performs the merging.

    Note that LightInject comes in two flavors, the source version where all the types are internal and the binary version that acts just like any other third party dependency.

    Taking on a dependency might not seem so bad at first, but if you are a framework developer, you could easily run into issues if the consumer of your framework uses another version of the same dependency

    Best regards

    Bernhard Richter