/// <summary> /// Registers the type. /// </summary> /// <typeparam name = "TFrom">The type of from.</typeparam> /// <typeparam name = "TTo">The type of to.</typeparam> public void RegisterServiceType <TFrom, TTo>() { if (_toResolve.ContainsKey(typeof(TFrom))) { throw new MvxException("Type already register"); } Type type = typeof(TTo); _toResolve.Add(typeof(TFrom), type); //// Adrian Sudbury extended code 31st Jan 2013 //// Here we are looking for constructors decorated with the attribute MvxOpenNetCfInjectionAttribute. IEnumerable <ConstructorInfo> constructors = (type.GetConstructors( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where( c => c.IsPublic && c.GetCustomAttributes( typeof(MvxOpenNetCfInjectionAttribute), true) .Any())); if (constructors.Any()) { //// If we find decorated constructor build type now. //// This was the only way i could get it to work - //// i couldnt see how to do deffered object construction. MvxOpenNetCfObjectBuilder.CreateObject(type); } //// End of extended code. }
private TToResolve CreateInstance <TToResolve>(Type typeToBuild) where TToResolve : class { #if NETFX_CORE if (typeToBuild.GetTypeInfo().IsInterface) { typeToBuild = _toResolve[typeToBuild]; } #else if (typeToBuild.IsInterface) { typeToBuild = _toResolve[typeToBuild]; } #endif var instance = MvxOpenNetCfObjectBuilder.CreateObject(typeToBuild); return((TToResolve)instance); }
/// <summary> /// Create a new instance at each time /// </summary> /// <returns></returns> public object GetInstance(Type typeToBuild) { var instance = MvxOpenNetCfObjectBuilder.CreateObject(typeToBuild); return(instance); }