interface ISampleService { void DoSomething(); } class SampleService : ISampleService { public void DoSomething() { Console.WriteLine("Doing something..."); } } var container = new TinyIoCContainer(); container.Register(); var service = container.Resolve (); service.DoSomething();
class Foo { private readonly ISomeService someService; public Foo(ISomeService someService) { this.someService = someService; } public void DoSomething() { this.someService.Do(); } } var container = new TinyIoCContainer(); container.RegisterIn this example, we define a class 'Foo' that has a dependency on an interface 'ISomeService.' We register the interface implementation class 'SomeService' and the 'Foo' class with the container. Finally, we resolve an instance of the 'Foo' class using the Resolve method and call its 'DoSomething' method. Package library: TinyIoCContainer In conclusion, TinyIoCContainer is a popular package library that enables developers to implement lightweight IoC containers in C# code. It provides a few simple methods, including Resolve, that make dependency injection easy and efficient.(); container.Register (); var foo = container.Resolve (); foo.DoSomething();