Created
August 2, 2021 20:54
-
-
Save techtheriac/2563b7ff4b4388b0ea9d9ffdab61fbfd to your computer and use it in GitHub Desktop.
Simple IOC Implementation Using Autofac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using IOCExploration.Implementations; | |
using IOCExploration.Interfaces; | |
using System.Reflection; | |
using Autofac; | |
namespace IOCExploration | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var container = BuildContainer(); | |
using(var scope = container.BeginLifetimeScope()) | |
{ | |
scope.Resolve<Application>().Run(); | |
} | |
} | |
private static IContainer BuildContainer() | |
{ | |
// Registering Individual Dependencies | |
var builder = new ContainerBuilder(); | |
builder.RegisterType<Application>(); | |
builder.RegisterType<Person>(); | |
//builder.RegisterType<Logger>().As<ILogger>(); | |
// Registering Automatically | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.AsSelf() | |
.AsImplementedInterfaces(); | |
return builder.Build(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment