Skip to content

Instantly share code, notes, and snippets.

@techtheriac
Created August 2, 2021 20:54
Show Gist options
  • Save techtheriac/2563b7ff4b4388b0ea9d9ffdab61fbfd to your computer and use it in GitHub Desktop.
Save techtheriac/2563b7ff4b4388b0ea9d9ffdab61fbfd to your computer and use it in GitHub Desktop.
Simple IOC Implementation Using Autofac
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