I know what a func is, but not able to understand the following piece of code:
There’s a simple property :
public Func<DomainFacade> BusinessFacadeFactory { get; set; }
And this is how the property is set:
this.BusinessFacadeFactory = () => new DomainFacade();
Now this way of setting the property, is it a Anonymous method or something else?
() => new DomainFacade()is a lambda expressionIt is an unnamed method written in place of a
delegateThe compiler converts it to a delegate instance
It’s real format is
(parameter)=>expression or a statement blockSince the
funcrequires adelegateto be assigned we can write alambda expressioninstead of thedelegatewhich would internally get converted to a delegate instance.So,
()denotes a an empty parameternew DomainFacade();is the expressionthat internally gets converted to delegate by the compiler