Hi I use Autofac for Dependency injection with DNN (7.4+)
I use ChrisHammond Template.
https://github.com/ChrisHammond/DNNTemplates
You need to manually Install Autofac and WebActivatorEx from Nuget
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(purplecs.Modules.MedulawPodcast.Bindings), "RegisterServices")]
namespace purplecs.Modules.MedulawPodcast
{
public class Bindings
{//
public static IContainer Container { get; set; }
public static void RegisterServices()
{
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where((x) => x.Name.EndsWith("Repository"))
.AsSelf();
Container = builder.Build();
}
}
}
I use the above Code to Registering My business logic Classes.
I also create a base Class for Portal Module Base
public classTModuleBase : PortalModuleBase
{
public TModuleBase()
{
Bindings.Container.InjectUnsetProperties(this);
// CheckSettings();
}
}
I my ascx file I Inherit my TModuleBase
public partial class TascxClass: TModuleBase
{
public TRepository tRepo {get;set;}
}
I use Property Injection method to inject the objects.
I suppose the same approach can be used for A MVC application too
Hope this helps