public DependencyCollection AddDependency(Type[] contracts, Type implementation, DependencyLifetime lifetime) { var resolver = DependencyResolver.Build(lifetime, implementation, _engine); var dependency = Dependency.Build(lifetime, contracts, resolver); return(AddDependency(dependency)); }
public IDependency BuildDependency(Type contract, IDependencyEngine engine) { var contractGenericArgs = contract.GenericTypeArguments; var notificationType = contractGenericArgs[0]; var processorType = typeof(INotificationProcessor <>).MakeGenericType(contractGenericArgs); var dependencies = engine.GetApplicable(processorType); var dependenciesLength = dependencies.Length; var pipelineType = dependenciesLength switch { 0 => throw Error.DependencyNotRegistered(processorType), 1 => typeof(NotificationSimplePipeline <>), _ => ParallelAttribute.IsDefined(notificationType) ? typeof(NotificationParallelPipeline <>) : typeof(NotificationSequentialPipeline <>) }; var implementation = pipelineType.MakeGenericType(contractGenericArgs); var lifetime = dependencies.DefineLifetime(); var resolver = DependencyResolver.Build(lifetime, implementation); return(Dependency.Build(lifetime, new[] { contract }, resolver)); } }
public IDependency BuildDependency(Type contract, IDependencyEngine engine) { var contracts = new[] { contract }; if (_nullServicePredicate != null && _nullServicePredicate(engine)) { return(new InstanceDependency(contracts, Activator.CreateInstance(_nullService))); } var lifetime = _lifetime ?? engine.DefineLifetime(_implementation); var resolver = DependencyResolver.Build(lifetime, _implementation); return(Dependency.Build(lifetime, contracts, resolver)); }
public IDependency BuildDependency(Type contract, IDependencyEngine engine) { var constructor = ReflectionUtils.GetConstructor(contract); var parameters = constructor.GetParameters(); var dependencies = new LocalList <IDependency>(); foreach (var parameter in parameters) { var required = !parameter.HasDefaultValue; var dependency = engine.GetDependency(parameter.ParameterType, required); dependencies.Add(dependency); } var lifetime = dependencies.DefineLifetime(); var resolver = DependencyResolver.Build(lifetime, contract, engine); return(Dependency.Build(lifetime, new[] { contract }, resolver)); }
public IDependency BuildDependency(Type contract, IDependencyEngine engine) { var systemType = contract.GenericTypeArguments[0]; var dependencies = engine.GetApplicable(systemType); var contracts = new[] { contract }; if (dependencies.Length == 0) { var nullHandlerType = typeof(SystemNullPipeline <>).MakeGenericType(systemType); var nullHandler = Activator.CreateInstance(nullHandlerType); return(new InstanceDependency(contracts, nullHandler)); } var handlerType = DefineHandlerType(dependencies); var implementation = handlerType.MakeGenericType(systemType); var lifetime = dependencies.DefineLifetime(); var resolver = DependencyResolver.Build(lifetime, implementation); return(Dependency.Build(lifetime, contracts, resolver)); }