YairHalberstadt / stronginject

compile time dependency injection for .NET
MIT License
849 stars 24 forks source link

[wiki] Fix "compile errors" in Containers.md #79

Closed arphox closed 3 years ago

arphox commented 3 years ago

I suggest trying all code examples before publishing them to the wiki. I fixed these kinds of errors in the Containers.md file.

Also, I don't know if the code snippets are meant to be runnable, but:

  1. If you are using "top level programs" feature of C# to run this, that won't work since code should be first, defined classes afterwards, so the code in the wiki does not compile.
  2. Maybe it would be better to have a console application example, but there we would need more code, example:
    
    using System;
    using StrongInject;

namespace Examples { [Register(typeof(A))] public partial class MyContainer : IContainer { }

public class A : IDisposable { public void Dispose() { } }

static class Program
{
    static void Main()
    {
        var myContainer = new MyContainer();
        myContainer.Run(a => Console.WriteLine($"We've resolved an instance of A: {a.ToString()}!!"));
    }
}

}

YairHalberstadt commented 3 years ago

I suggest trying all code examples before publishing them to the wiki. I fixed these kinds of errors in the Containers.md file.

Oops 😳!

I think I fixed up most of the examples in the wiki recently, but I must have missed this one. Thanks!

Also, I don't know if the code snippets are meant to be runnable, but:

Not sure. I see the benefit to making them runnable, but I like the current order where I first show the code, then explain what happens. I don't want all the boilerplat of a main method. Will have to think about it.