private DependencyBinder ConstructBinder(Type type, Type proxy, object instance, DependencyBindingOptions options) { if (type != null && instance != null) { throw new InvalidOperationException("both type and instance can't have a value"); } DependencyBinder binder; if (instance != null) { binder = new DependencyBinder(options, instance); } else if (type != null) { binder = new DependencyBinder(options, type); } else { throw new InvalidOperationException("construction requires type of instance to continue"); } var resolver = new DependencyBindingResolver(this); if (proxy != null) { binder.AsProxy(proxy); } if (instance == null) { if (!resolver.ResolveActivator(type, out var activator)) { throw new DependencyBinderException(type, $"no activator for type {type.Name} could be created, please " + $"check that the type has a public parameterless default " + $"constructor or binding constructor available"); } binder.BindWith(activator); } if (!resolver.ResolveBindings(type ?? instance?.GetType(), out var bindings)) { return(binder); } binder.BindWith(bindings); return(binder); }
static InternalFactory() { IDependencyRepository dependencies = new DependencyRepository(); IDependencyInjector injector = new DependencyInjector(dependencies); IDependencyBinder binder = new DependencyBinder(dependencies, injector); IMultiBindCollection multiBindMap = new MultiBindCollection(); singletons = new Dictionary <Type, object> { { typeof(IDependencyRepository), dependencies }, { typeof(IDependencyInjector), injector }, { typeof(IDependencyBinder), binder }, { typeof(IMultiBindCollection), multiBindMap }, }; }
private static bool ConstructDependency(DependencyBinder binder, out Dependency dependency) { dependency = null; if (!binder.Bind()) { return(false); } var options = binder.Options; var strict = (options & DependencyBindingOptions.Strict) == DependencyBindingOptions.Strict; dependency = binder.Proxy != null ? new Dependency(binder.Instance, DependencyTypeMapper.Map(binder.Proxy, options), strict) : new Dependency(binder.Instance, DependencyTypeMapper.Map(binder.Type, options), strict); return(true); }
public App() { _viewModelsBinder = new ViewModelsBinder(); _dependencyBinder = new DependencyBinder(); _modulesBinder = new ModulesBinder(); }