private void RegisterService(Type serviceType, Type implementationType, string name, LifetimeType lifetime = LifetimeType.Transient, object constructorArgsAsAnonymousType = null, IfAlreadyRegistered ifAlreadyRegistered = IfAlreadyRegistered.AppendNotKeyed) { Ensure.NotNull(serviceType, nameof(serviceType)); Ensure.NotNull(implementationType, nameof(implementationType)); Made made = null; if (constructorArgsAsAnonymousType != null) { made = GetParameterSelector(constructorArgsAsAnonymousType); } _container.Register(serviceType: serviceType, implementationType: implementationType, reuse: ConvertLifetimeToReuse(lifetime), made: made, serviceKey: name, ifAlreadyRegistered: ifAlreadyRegistered); //接口拦截 if (_interceptType.IsAssignableFrom(serviceType) && serviceType.GetTypeInfo().IsInterface) { PipelineManager.Instance.InterceptByInterface(implementationType); _container.Intercept <DynamicProxyInterceptor>(serviceType, name); } else if (_interceptType.IsAssignableFrom(implementationType)) //虚方法拦截 { PipelineManager.Instance.InterceptByVirtualMethod(implementationType); _container.Intercept <DynamicProxyInterceptor>(implementationType, name); } }
public static void ScanAssemblies <T>(this IRegistrator registrator, IReuse reuse = null, Made made = null, Setup setup = null, IfAlreadyRegistered ifAlreadyRegistered = IfAlreadyRegistered.AppendNotKeyed) { var serviceTypeOf = typeof(T); var scannedTypes = AssemblyFinder.ScanAssemblies() .Where(assembly => { try { return(assembly.DefinedTypes != null); } catch { return(false); } }) .SelectMany(assembly => assembly.DefinedTypes) .Where(type => !type.IsAbstract && serviceTypeOf.GetTypeInfo() .IsAssignableFrom(type)); foreach (var eachScannedType in scannedTypes) { registrator.Register(eachScannedType.AsType(), reuse, made, setup, ifAlreadyRegistered); var interfaces = eachScannedType.ImplementedInterfaces; foreach (var eachInterface in interfaces) { registrator.Register(eachInterface, eachScannedType.AsType(), reuse, made, setup, ifAlreadyRegistered); } } }
public void Register(Factory factory, Type serviceType, object serviceKey, IfAlreadyRegistered ifAlreadyRegistered, bool isStaticallyChecked) { throw new NotImplementedException(); }
public void UseInstance(Type serviceType, object instance, IfAlreadyRegistered IfAlreadyRegistered, bool preventDisposal, bool weaklyReferenced, object serviceKey) { throw new NotImplementedException(); }