Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDependency InjectionDependency Injection
Previous
 
Next
New Post
6/19/2017 9:40 PM
 

Can someone give me some guidance on setting up and using DNN's dependency injection? 

As far as I understand there ComponentModel.ComponentFactory class to be used for this purpose, but I am unable to find a good source on usage. I am using Asp.Net WebForms and DNN 7.4. I am using the DAL DNN Module Template.

1) How do I use it?

2) Where do I register my classes?

3) How can I choose my instance lifetime?

4) How do I can dependencies?

5) Are there any tutorials or documentation?

 
New Post
6/20/2017 5:11 PM
 
Please forgive my typo, #4 should be:

How do I register my chained dependencies?

e.g. Dependencies with dependencies
ClassA
ClassB(IClassA a)
ClassC(IClassB C)

 
New Post
6/20/2017 10:55 PM
 

Clarification on #4: How do I "chain" dependencies? How can I use the container to provide dependencies to other dependencies in the container? e.g. ClassA(), ClassB(IClassA A), ClassC(IClassB B), etc...

 
New Post
6/22/2017 10:43 AM
 
Hi I use Autofac for Dependency injection with DNN (7.4+)
I use ChrisHammond Template.
https://github.com/ChrisHammond/DNNTe...

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





 
New Post
6/22/2017 10:43 AM
 
Hi I use Autofac for Dependency injection with DNN (7.4+)
I use ChrisHammond Template.
https://github.com/ChrisHammond/DNNTe...

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





 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDependency InjectionDependency Injection


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out