Click here to Skip to main content
15,887,376 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionFXCop (VS 2013 Pro) and private P/Invoke methods Pin
obermd22-Mar-14 12:00
obermd22-Mar-14 12:00 
AnswerRe: FXCop (VS 2013 Pro) and private P/Invoke methods Pin
Eddy Vluggen26-Mar-14 8:10
professionalEddy Vluggen26-Mar-14 8:10 
GeneralRe: FXCop (VS 2013 Pro) and private P/Invoke methods Pin
obermd26-Mar-14 8:56
obermd26-Mar-14 8:56 
GeneralRe: FXCop (VS 2013 Pro) and private P/Invoke methods Pin
obermd26-Mar-14 13:31
obermd26-Mar-14 13:31 
QuestionError on System.Web.Helpers.WebMail.Send() method in TFS 2012 Pin
trevor1519-Mar-14 4:04
trevor1519-Mar-14 4:04 
AnswerRe: Error on System.Web.Helpers.WebMail.Send() method in TFS 2012 Pin
Richard MacCutchan19-Mar-14 4:19
mveRichard MacCutchan19-Mar-14 4:19 
QuestionGetting "Handle" of DirectX Output inside a WPF Window/Containter... Pin
Christopher Koeber18-Mar-14 11:29
Christopher Koeber18-Mar-14 11:29 
QuestionIOCContainer nested dependencies and failed resolves Pin
preaa10-Mar-14 23:38
preaa10-Mar-14 23:38 
Hello All,

I am working on the correct usage of IOCContainer(Autofac) in a project which has mulitple assemblies. I am not able to understand the nested dependency pattern correctly as well as what would be the best exception handling strategy in case of failed resolves.

The post is not concise, as I am afraid I cannot explain my confusion in a brief manner. So apologies..

I am trying to use the 'constructor injection pattern' instead of 'property' or 'method' injection. so a class which looked like this:

C#
Class Foo()
{
private static readonly IDependency = IOCContainer.Resolve<IDependency>();
}


is changed to something like this

C#
Class Foo(IDependency dependency)
{
private readonly IDependency = dependency;
}


however after cleaning up the whole code with the constructor pattern, the code looks like this

C#
Class Foo(){
public Foo(IDependency dependency)
{
      this.dependency = dependency;
      ....
      var bar = new Bar(this.dependency);
    
    }
}
    
Class Bar{

    public Bar(IDependency dependency)
    {
     this.dependency = dependency;
    
    }
}


Now if the dependency was not available (IOCContainer failed to resolve this dependency), Foo will pass that dependency around, without worrying about the failed resolved call..

I think that given this scenario, the property or method injection methods seem correct as all the classes are directly calling IOCContainer resolves and then they would have a way to check if the dependency was resolved or not directly from the IOCContainer.

However A null check or a try catch can be applied when we access the dependency anyways even with the constructor injection pattern, for e.g.

C#
class Bar()
{
public SomeMethod()
     {
     (dependency != null ? dependency.doSomething : throw new  Exception(DependencyNotAvailable);
     }
}


Is it correct approach? How should I handle the exceptions from IOCContainer otherwise?

Thanks in advance,
Preaa
AnswerRe: IOCContainer nested dependencies and failed resolves Pin
Pete O'Hanlon11-Mar-14 12:05
mvePete O'Hanlon11-Mar-14 12:05 
GeneralRe: IOCContainer nested dependencies and failed resolves Pin
preaa11-Mar-14 21:38
preaa11-Mar-14 21:38 
GeneralRe: IOCContainer nested dependencies and failed resolves Pin
Pete O'Hanlon11-Mar-14 21:50
mvePete O'Hanlon11-Mar-14 21:50 
QuestionCréation d'un outil intelligent pour la vidéosurveillance" with vb.net 2008 Pin
Sahal Meriem10-Mar-14 9:32
Sahal Meriem10-Mar-14 9:32 
AnswerRe: Création d'un outil intelligent pour la vidéosurveillance" with vb.net 2008 Pin
Dave Kreskowiak10-Mar-14 10:11
mveDave Kreskowiak10-Mar-14 10:11 
QuestionError: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
Member 105062157-Mar-14 3:12
Member 105062157-Mar-14 3:12 
AnswerRe: Error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
Richard MacCutchan7-Mar-14 7:25
mveRichard MacCutchan7-Mar-14 7:25 
GeneralRe: Error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
Member 1050621510-Mar-14 4:30
Member 1050621510-Mar-14 4:30 
GeneralRe: Error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
melquimoises10-Mar-14 12:15
melquimoises10-Mar-14 12:15 
GeneralRe: Error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
melquimoises28-Mar-14 6:46
melquimoises28-Mar-14 6:46 
GeneralRe: Error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
melquimoises28-Mar-14 6:46
melquimoises28-Mar-14 6:46 
GeneralRe: Error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
melquimoises28-Mar-14 6:47
melquimoises28-Mar-14 6:47 
AnswerRe: Error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
knocky20108-Mar-14 22:14
knocky20108-Mar-14 22:14 
AnswerRe: Error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
Richard Deeming10-Mar-14 2:11
mveRichard Deeming10-Mar-14 2:11 
GeneralRe: Error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible' Pin
Member 1050621510-Mar-14 4:35
Member 1050621510-Mar-14 4:35 
Questionhow to get connection strings in web api 4.0 from app.config file Pin
rincy sivan7-Mar-14 0:05
rincy sivan7-Mar-14 0:05 
AnswerRe: how to get connection strings in web api 4.0 from app.config file Pin
Richard MacCutchan7-Mar-14 0:12
mveRichard MacCutchan7-Mar-14 0:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.