/// <summary> /// Retrieves a new instance of the type stored in the given <see cref="ActivationParams"/>. /// </summary> /// <param name="parameters">The parameters that describe the type that should be instantiated.</param> /// <returns>Returns the new object.</returns> public static object CreateObject(ActivationParams parameters) { var obj = Locator.Current.GetService(parameters.Type); if (obj == null) { throw new InvalidOperationException($"Could not resolve an object of type: {parameters.Type} because Locator.Current.GetService({parameters.Type}) returned null. Make sure you have registered a factory for the type using Locator.CurrentMutable.Register(factory, {parameters.Type})"); } return(obj); }
private async Task <Transition> BuildViewModelAsync(ActivationParams activationParams) { var vm = await ActivationHelpers.CreateAndInitObjectAsync(activationParams); var transition = new Transition() { ViewModel = vm }; return(transition); }
/// <summary> /// Instantiates and initializes the object described by the given <see cref="ActivationParams"/>. /// </summary> /// <param name="parameters">The parameters that should be used to initialize the object.</param> /// <returns>Returns the created object.</returns> public static async Task <object> CreateAndInitObjectAsync(ActivationParams parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } var obj = CreateObject(parameters); await InitObjectAsync(obj, parameters.Params); return(obj); }
/// <summary> /// Instantiates and initializes the object described by the given <see cref="ActivationParams"/>. /// </summary> /// <param name="parameters">The parameters that should be used to initialize the object.</param> /// <returns>Returns the created object.</returns> public static async Task <T> CreateAndInitObjectAsync <T, TParams>(TParams parameters) where T : IActivatable <TParams> where TParams : new() { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } var activationParams = new ActivationParams() { Type = typeof(T), Params = parameters }; return((T) await CreateAndInitObjectAsync(activationParams)); }