public MongoDatabase Create(Type type, IIocContext context) { Type entityType = type; if (type.IsGenericType) { entityType = type.GetGenericArguments()[0]; } string connString = null; string dbName = null; var entitySet = entitySets.FirstOrDefault(o => o.EntityTypes.Any(e => e.Equals(entityType))); if (entitySet != null) { connString = ConfigurationManager.ConnectionStrings[entitySet.ConnectionString].ConnectionString; dbName = entitySet.ConnectionString; } else { connString = ConfigurationManager.ConnectionStrings["mongodb"].ConnectionString; dbName = type.AssemblyName().Replace(".", "_"); } var server = MongoServer.Create(connString); var db = server.GetDatabase(dbName); return(db); }
public DbContext Create(Type type, IIocContext context) { Type entityType = type; if (type.IsGenericType) { entityType = type.GetGenericArguments()[0]; } if (!DbContextConfig.EentityTypeToDbContextType.ContainsKey(entityType)) { throw new Exception(string.Format("type of {0} has not yet configered.", entityType.FullName)); } var dbType = DbContextConfig.EentityTypeToDbContextType[entityType]; var db = Activator.CreateInstance(dbType) as DbContext; return(db); }
public IDataContext Create(Type type, IIocContext context) { Type entityType = type; if (type.IsGenericType) { entityType = type.GetGenericArguments()[0]; } var entitySet = entitySets.FirstOrDefault(o => o.EntityTypes.Any(e => e.Equals(entityType))); if (entitySet == null) { throw new Exception(string.Format("type of {0} has not yet configered.", entityType.FullName)); } var db = new DataContext(entitySet.ConnectionString); ((DataContext)db).MappingSchema = new DefaultMappingSchema(); return(db); }
public static IEnumerable <T> ResolveAll <T>(this IIocContext context) { return(context.ResolveAll(typeof(T)).Select(o => (T)o)); }
public static T ResolveOptional <T>(this IIocContext context, string name = null) { return((T)context.ResolveOptional(typeof(T), name)); }
public static bool IsRegistered <T>(this IIocContext context, string name = null) { return(context.IsRegistered(typeof(T), name)); }