Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 public static IEnumerable <T> ResolveAll <T>(this IIocContext context)
 {
     return(context.ResolveAll(typeof(T)).Select(o => (T)o));
 }
Beispiel #5
0
 public static T ResolveOptional <T>(this IIocContext context, string name = null)
 {
     return((T)context.ResolveOptional(typeof(T), name));
 }
Beispiel #6
0
 public static bool IsRegistered <T>(this IIocContext context, string name = null)
 {
     return(context.IsRegistered(typeof(T), name));
 }