protected abstract void RegisterTypes(ICodeBrixContainer container);
protected virtual void RegisterModules(ICodeBrixContainer container) { }
protected override void RegisterTypes(ICodeBrixContainer container) { container.RegisterForNavigation <MainPage>(); }
public override void RegisterTypes(ICodeBrixContainer container) { //Register any platform-specific types here }
internal static object GetInstance(ICodeBrixContainer container, Type type, bool isSingleton, NamedParameter[] namedParameters = null, Dictionary <string, object> settings = null) { if (type == null) { throw new ArgumentNullException(nameof(type)); } bool addToSingletons = false; if (isSingleton) { lock (singletonLocker) { if (singletons.ContainsKey(type)) { return(singletons[type]); } else { addToSingletons = true; } } } if (IsSimpleType(type)) { return(Activator.CreateInstance(type)); } //Type is a reference type, need to try to create an instance object instance = null; string unregisteredType = null; namedParameters = namedParameters ?? new NamedParameter[] { }; IEnumerable <ConstructorInfo> ctors = type.GetTypeInfo().DeclaredConstructors ?? new List <ConstructorInfo>(); // ReSharper disable PossibleMultipleEnumeration // Will first try to find a compatible constructor *with* parameters foreach (ConstructorInfo ctor in ctors.Where(w => (w.GetParameters()?.Length ?? 0) > 0)) { ParameterInfo[] ctorParams = ctor.GetParameters() ?? new ParameterInfo[] { }; if (ctorParams.All(a => namedParameters.Any(n => n.Name.Equals(a.Name, StringComparison.CurrentCultureIgnoreCase)) || container.IsRegistered(a.ParameterType) || ((container as CodeBrixContainer)?.XamarinDependencyExists(a.ParameterType) ?? false))) { var parameters = new List <object>(); foreach (ParameterInfo ctorParam in ctorParams) { parameters.Add(namedParameters.FirstOrDefault(f => f.Name.Equals(ctorParam.Name, StringComparison.CurrentCultureIgnoreCase))?.Value ?? container.Resolve(ctorParam.ParameterType, namedParameters)); } instance = ctor.Invoke(parameters.ToArray()); break; } else { unregisteredType = unregisteredType ?? ctorParams.FirstOrDefault(f => namedParameters.All(n => !n.Name.Equals(f.Name, StringComparison.CurrentCultureIgnoreCase)) && (!container.IsRegistered(f.ParameterType)))?.ParameterType?.Name; } } //Next, will try to create our instance using the default constructor instance = instance ?? FindDefaultConstructor(ctors)?.Invoke(new object[] { }); // ReSharper restore PossibleMultipleEnumeration if (instance == null) { throw new InvalidOperationException($"An instance of type '{type.Name}' could not be constructed" + $"{(unregisteredType == null ? "" : $" - the constructor parameter type of '{unregisteredType}' appears to be unregistered")}."); }
public override void RegisterTypes(ICodeBrixContainer container) { //Perform any type or page or service registration required by the module here container.RegisterForNavigation <SamplePage>(); }
/// <summary> /// Registers a Page for navigation. /// </summary> /// <typeparam name="TView">The Type of Page to register</typeparam> /// <typeparam name="TViewModel">The ViewModel to use as the BindingContext for the Page</typeparam> /// <param name="name">The unique name to register with the Page</param> /// <param name="container"></param> public static void RegisterForNavigation <TView, TViewModel>(this ICodeBrixContainer container, string name = null) where TView : Page where TViewModel : class { container.RegisterForNavigationWithViewModel <TViewModel>(typeof(TView), name); }
public static void RegisterModule <T>(this ICodeBrixContainer container, ICodeBrixModuleInfo <T> moduleInfo) where T : ICodeBrixModule { container.RegisterSingleton(new ObjectFactory(moduleInfo.ModuleType, true, moduleInfo.Settings), moduleInfo.ModuleType, moduleInfo.ModuleName); (container as CodeBrixContainer)?.ModuleCatalog?.AddModule(moduleInfo.ModuleInfo); }
internal static void SetDefaultContainer(ICodeBrixContainer container) { _defaultContainer = container; }
public DynamicTabbedPage(ICodeBrixContainer container) { InitializeComponent(); _container = container; }
public virtual void RegisterTypes(ICodeBrixContainer container) { }