/// <summary> /// Dispose /// </summary> /// <param name="iocResolve"></param> public virtual void Dispose(IIocResolve iocResolve) { foreach (var activeTransaction in ActiveTransations.Values) { foreach (var attendedDbContext in activeTransaction.AttendedDbContexts) { iocResolve.Release(attendedDbContext); } activeTransaction.DbContextTransaction.Dispose(); iocResolve.Release(activeTransaction.StartDbContext); } //清除事务 ActiveTransations.Clear(); foreach (var dbContext in DbContexts) { iocResolve.Release(dbContext); } //清除DbContexts DbContexts.Clear(); if (CurrentTransaction == null) { return; } CurrentTransaction.Dispose(); CurrentTransaction = null; }
/// <summary> /// This method can be used to resolve and release an object automatically. /// You can use the object in <paramref name="func"/> and return a value. /// </summary> /// <typeparam name="TService">Type of the service to use</typeparam> /// <typeparam name="TReturn">Return type</typeparam> /// <param name="iocResolver">IIocResolver object</param> /// <param name="func">A function that can use the resolved object</param> public static TReturn Using <TService, TReturn>(this IIocResolve iocResolver, Func <TService, TReturn> func) { using (var obj = iocResolver.ResolveAsDisposable <TService>()) { return(func(obj.Object)); } }
/// <summary> /// This method starts a scope to resolve and release all objects automatically. /// You can use the <c>scope</c> in <see cref="action"/>. /// </summary> /// <param name="iocResolver">IIocResolver object</param> /// <param name="action">An action that can use the resolved object</param> public static void UsingScope(this IIocResolve iocResolver, Action <IScopedIocResolver> action) { using (var scope = iocResolver.CreateScope()) { action(scope); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="efTransactionStrategy"></param> /// <param name="iocResolve"></param> public EfUnitOfWork(IEfTransactionStrategy efTransactionStrategy, IIocResolve iocResolve) { _efTransactionStrategy = efTransactionStrategy; IocResolve = iocResolve; ActiveDbContexts = new Dictionary <string, DbContext>(); }
/// <summary> /// This method can be used to resolve and release an object automatically. /// You can use the object in <paramref name="action"/>. /// </summary> /// <typeparam name="T">Type of the object to use</typeparam> /// <param name="iocResolver">IIocResolver object</param> /// <param name="action">An action that can use the resolved object</param> public static void Using <T>(this IIocResolve iocResolver, Action <T> action) { using (var wrapper = iocResolver.ResolveAsDisposable <T>()) { action(wrapper.Object); } }
public DbContext CreateDbContex <TDbContext>(string connectionString, IIocResolve iocResolve) where TDbContext : DbContext { DbContext dbContext; ActiveTransactionInfo activeTransaction; activeTransaction = ActiveTransations.TryGetValue(connectionString, out activeTransaction) ? activeTransaction : default(ActiveTransactionInfo); if (activeTransaction == null)//没找到则ioc通过NamedParameter创建一个 { dbContext = iocResolve.ResolveParameter <TDbContext>(new NamedParameter("nameOrConnectionString", connectionString)); var dbTransaction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted); activeTransaction = new ActiveTransactionInfo(dbTransaction, dbContext); ActiveTransations[connectionString] = activeTransaction; } else//找到了则通过ioc把DbConnection作为参数创建一个DbContext { dbContext = iocResolve.ResolveParameter <TDbContext>(new Parameter[] { new NamedParameter("existingConnection", activeTransaction.DbContextTransaction.UnderlyingTransaction.Connection), new NamedParameter("contextOwnsConnection", false) }); //通过connection参数resolve一个dbcontext对象 //dbContext = iocResolve.ResolveParameter<TDbContext>(new TypedParameter(typeof(DbConnection), //activeTransaction.DbContextTransaction.UnderlyingTransaction.Connection)); dbContext.Database.UseTransaction(activeTransaction.DbContextTransaction.UnderlyingTransaction); activeTransaction.AttendedDbContexts.Add(dbContext); } DbContexts.Add(dbContext); return(dbContext); }
public static IIocResolve Resolve(IIocConfig config) { if (_resolve == null) { _resolve = new IocResolve(config); } return _resolve; }
public static IIocResolve Resolve(IIocConfig config) { if (_resolve == null) { _resolve = new IocResolve(config); } return(_resolve); }
public EfUnitOfWork(IIocResolve iocResolver, IUnitOfWorkDefaultOptions defaultOptions, IConnectionStringResolver connectionStringResolver, IEfTransactionStrategy transactionStrategy, IDbContextTypeMatcher dbContextTypeMatche, IDbContextResolver dbContextResolver) : base(connectionStringResolver) { IocResolver = iocResolver; _transactionStrategy = transactionStrategy; _dbContextTypeMatcher = dbContextTypeMatche; _dbContextResolver = dbContextResolver; _activeDbContexts = new Dictionary <Type, DbContext>(); }
public EddoLoginManager(EddoUserManage <TRole, TUser> userManage, EddoRoleManager <TRole, TUser> roleManage, IUnitOfWorkManage unitOfWorkManager, IRepository <UserLoginAttempt, long> userLoginAttemptRepository, IIocResolve iocResolver) { UserManager = userManage; RoleManager = roleManage; UnitOfWorkManager = unitOfWorkManager; UserLoginAttemptRepository = userLoginAttemptRepository; IocResolver = iocResolver; ClientInfoProvider = NullClientInfoProvider.Instance; }
static void Main(string[] args) { IIocConfig config = new IocConfig(); config.AddConfig <ITest, Test>(); IIocResolve resolve = IocManager.Resolve(config); ITest test = resolve.Resolve <ITest>(); test.Name = "hy"; test.Do(); }
public virtual void Dispose(IIocResolve iocResolver) { foreach (var dbContext in DbContexts) { iocResolver.Release(dbContext); } DbContexts.Clear(); if (CurrentTransaction != null) { CurrentTransaction.Dispose(); CurrentTransaction = null; } }
private static string GetNameOrConnectionStringOrNull(IIocResolve iocResolver) { if (iocResolver.IsRegistered <IEddoStartupConfiguration>()) { var defaultConnectionString = iocResolver.Resolve <IEddoStartupConfiguration>().DefaultNameOrConnectionString; if (!string.IsNullOrWhiteSpace(defaultConnectionString)) { return(defaultConnectionString); } } if (ConfigurationManager.ConnectionStrings.Count == 1) { return(ConfigurationManager.ConnectionStrings[0].Name); } if (ConfigurationManager.ConnectionStrings["Default"] != null) { return("Default"); } return(null); }
public DefaultDbContextResolver(IIocResolve iocResolver, IDbContextTypeMatcher dbContextTypeMatcher) { _iocResolver = iocResolver; _dbContextTypeMatcher = dbContextTypeMatcher; }
public UnitOfWorkManager(IIocResolve iocResolve, ICurrentUnitOfWorkProvider currentUnitOfWorkProvider) { _iocResolve = iocResolve; _currentUnitOfWorkProvider = currentUnitOfWorkProvider; }
/// <summary> /// 创建实例化WindsorControllerFactory /// </summary> /// <param name="iocManager">Reference to DI kernel</param> public WindsorControllerFactory(IIocResolve iocManager) { _iocManager = iocManager; }
/// <summary> /// Gets an <see cref="DisposableDependencyObjectWrapper{T}"/> object that wraps resolved object to be Disposable. /// </summary> /// <param name="iocResolver">IIocResolver object</param> /// <param name="type">Type of the object to resolve. This type must be convertible to <see cref="IDisposable"/>.</param> /// <param name="argumentsAsAnonymousType">Constructor arguments</param> /// <returns>The instance object wrapped by <see cref="DisposableDependencyObjectWrapper{T}"/></returns> public static IDisposableDependencyObjectWrapper ResolveAsDisposable(this IIocResolve iocResolver, Type type, object argumentsAsAnonymousType) { return(new DisposableDependencyObjectWrapper(iocResolver, iocResolver.Resolve(type, argumentsAsAnonymousType))); }
public LogInManager(UserManager userManage, RoleManager roleManage, IUnitOfWorkManage unitOfWorkManager, IRepository <UserLoginAttempt, long> userLoginAttemptRepository, IIocResolve iocResolver) : base(userManage, roleManage, unitOfWorkManager, userLoginAttemptRepository, iocResolver) { }
public DisposableDependencyObjectWrapper(IIocResolve iocResolver, object obj) : base(iocResolver, obj) { }
/// <summary> /// Gets an <see cref="DisposableDependencyObjectWrapper{T}"/> object that wraps resolved object to be Disposable. /// </summary> /// <typeparam name="T">Type of the object to get</typeparam> /// <param name="iocResolver">IIocResolver object</param> /// <returns>The instance object wrapped by <see cref="DisposableDependencyObjectWrapper{T}"/></returns> public static IDisposableDependencyObjectWrapper <T> ResolveAsDisposable <T>(this IIocResolve iocResolver) { return(new DisposableDependencyObjectWrapper <T>(iocResolver, iocResolver.Resolve <T>())); }
/// <summary> /// Gets an <see cref="DisposableDependencyObjectWrapper{T}"/> object that wraps resolved object to be Disposable. /// </summary> /// <param name="iocResolver">IIocResolver object</param> /// <param name="type">Type of the object to resolve. This type must be convertible to <see cref="IDisposable"/>.</param> /// <returns>The instance object wrapped by <see cref="DisposableDependencyObjectWrapper{T}"/></returns> public static IDisposableDependencyObjectWrapper ResolveAsDisposable(this IIocResolve iocResolver, Type type) { return(new DisposableDependencyObjectWrapper(iocResolver, iocResolver.Resolve(type))); }
/// <summary> /// Gets an <see cref="DisposableDependencyObjectWrapper{T}"/> object that wraps resolved object to be Disposable. /// </summary> /// <typeparam name="T">Type of the object to get</typeparam> /// <param name="iocResolver">IIocResolver object</param> /// <param name="argumentsAsAnonymousType">Constructor arguments</param> /// <returns>The instance object wrapped by <see cref="DisposableDependencyObjectWrapper{T}"/></returns> public static IDisposableDependencyObjectWrapper <T> ResolveAsDisposable <T>(this IIocResolve iocResolver, object argumentsAsAnonymousType) { return(new DisposableDependencyObjectWrapper <T>(iocResolver, iocResolver.Resolve <T>(argumentsAsAnonymousType))); }
public EventBusInstaller(IIocResolve iocResolver) { _iocResolver = iocResolver; _eventBusConfiguration = iocResolver.Resolve <IEventBusConfiguration>(); }
public UnitOfWorkManage(IIocResolve iocResolver, IUnitOfWorkProvider unitOfWorkProvider, IUnitOfWorkDefaultOptions defaultOptions) { _iocResolver = iocResolver; _unitOfWorkProvider = unitOfWorkProvider; _defaultOptions = defaultOptions; }
public ScopedIocResolver(IIocResolve iocResolver) { _iocResolver = iocResolver; _resolvedObjects = new List <object>(); }
public EddoApiControllerActivator(IIocResolve iocResolver) { _iocResolver = iocResolver; }
/// <summary> /// Gets a <see cref="ScopedIocResolver"/> object that starts a scope to resolved objects to be Disposable. /// </summary> /// <param name="iocResolver"></param> /// <returns>The instance object wrapped by <see cref="ScopedIocResolver"/></returns> public static IScopedIocResolver CreateScope(this IIocResolve iocResolver) { return(new ScopedIocResolver(iocResolver)); }