private static void RegisterDependency(this IServiceCollection services, List <Type> assemblies, List <DependencyMapping> dependencyMappings, Type attributeType, Type serviceType, Type implementationType = null) { if (!SupportedAttributes.Contains(attributeType)) { throw new NotSupportedException($"{attributeType.FullName} is not supported by dependency auto registration"); } if (implementationType == null) { implementationType = serviceType; } if (attributeType == typeof(Transient)) { services.AddTransient(serviceType, implementationType); } else if (attributeType == typeof(Scoped)) { services.AddScoped(serviceType, implementationType); } else if (attributeType == typeof(Singleton)) { services.AddSingleton(serviceType, implementationType); } var dependencyMapping = new DependencyMapping { AttributeType = attributeType, ServiceType = serviceType, ImplementationType = implementationType }; dependencyMappings.Add(dependencyMapping); }
private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>(); DependencyMapping.RegisterServices(kernel); return(kernel); }
public static IServiceProvider InitAutofac(IServiceCollection services) { // Create an Autofac Container and push the framework services var containerBuilder = new ContainerBuilder(); containerBuilder.Populate(services); // Register your own services within Autofac DependencyMapping.Initialize(containerBuilder); // Build the container and return an IServiceProvider from Autofac var container = containerBuilder.Build(); return(container.Resolve <IServiceProvider>()); }
// ReSharper disable once NotNullOnImplicitCanBeNull // ReSharper disable once AssignNullToNotNullAttribute protected void OnPropertyChanged([CallerMemberName][NotNull] string propertyName = null) { // ReSharper disable once AssignNullToNotNullAttribute InternalOnPropertyChanged(propertyName); if (!DependencyMapping.TryGetValue(propertyName, out var dependentProperties)) { return; } foreach (var dependentProperty in dependentProperties) { InternalOnPropertyChanged(dependentProperty); } }