Skip to content

Instantly share code, notes, and snippets.

@r4hulp
Last active December 29, 2017 12:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save r4hulp/ae7e4fc02f501e245325d9b1fc52d282 to your computer and use it in GitHub Desktop.
Dialog Factory
public interface IDialogFactory
{
//constructor without dynamic params
T Create<T>();
//Constructor requiring multiple dynamic params
T Create<T>(IDictionary<string, object> parameters);
}
public class DialogFactory : IDialogFactory
{
protected readonly IComponentContext Scope;
//IComponentContext does not need to be registered as Autofac automatically provides it.
public DialogFactory(IComponentContext scope)
{
SetField.NotNull(out this.Scope, nameof(scope), scope);
}
public T Create<T>()
{
return this.Scope.Resolve<T>();
}
public T Create<T>(IDictionary<string, object> parameters)
{
return this.Scope.Resolve<T>(parameters.Select(kv => new NamedParameter(kv.Key, kv.Value)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment