/// <summary> /// 注册动作。 /// </summary> /// <param name="builder">容器建造者。</param> /// <param name="blueprint">外壳蓝图。</param> public void Registrations(ContainerBuilder builder, ShellBlueprint blueprint) { foreach (var item in blueprint.GetControllers()) { var serviceKeyName = (item.AreaName + "/" + item.ControllerName).ToLowerInvariant(); var serviceKeyType = item.Type; RegisterType(builder, item) .Keyed<IController>(serviceKeyName) .Keyed<IController>(serviceKeyType) .WithMetadata("ControllerType", item.Type) .InstancePerDependency(); } foreach (var item in blueprint.GetHttpControllers()) { var serviceKeyName = (item.AreaName + "/" + item.ControllerName).ToLowerInvariant(); var serviceKeyType = item.Type; RegisterType(builder, item) .Keyed<IHttpController>(serviceKeyName) .Keyed<IHttpController>(serviceKeyType) .WithMetadata("ControllerType", item.Type) .InstancePerDependency(); } }
public StandardExtensionRouteProvider(ShellBlueprint blueprint) { _blueprint = blueprint; }
/// <summary> /// 创建一个外壳容器。 /// </summary> /// <param name="settings">外壳设置。</param> /// <param name="blueprint">外壳蓝图。</param> /// <returns>外壳容器。</returns> public ILifetimeScope CreateContainer(ShellSettings settings, ShellBlueprint blueprint) { var intermediateScope = _lifetimeScope.BeginLifetimeScope( builder => { //TODO:CollectionOrderModule、CacheModule 等Module是公共的,需要验证 Root 范围注册了子级生命范围是否生效,如果生效则在外壳容器中忽略掉这些Module foreach (var item in blueprint.Dependencies.Where(t => typeof(IModule).IsAssignableFrom(t.Type))) { RegisterType(builder, item) .Keyed<IModule>(item.Type) .InstancePerDependency(); } }); return intermediateScope.BeginLifetimeScope( "shell", builder => { builder.Register(ctx => settings); builder.Register(ctx => blueprint.Descriptor); builder.Register(ctx => blueprint); var moduleIndex = intermediateScope.Resolve<IIndex<Type, IModule>>(); foreach (var item in blueprint.Dependencies.Where(t => typeof(IModule).IsAssignableFrom(t.Type))) { builder.RegisterModule(moduleIndex[item.Type]); } foreach (var item in blueprint.Dependencies.Where(t => typeof(IDependency).IsAssignableFrom(t.Type))) { var registration = RegisterType(builder, item) .InstancePerLifetimeScope(); foreach (var interfaceType in item.Type.GetInterfaces() .Where(itf => typeof(IDependency).IsAssignableFrom(itf) && !typeof(IEventHandler).IsAssignableFrom(itf))) { registration = registration.As(interfaceType); if (typeof(ISingletonDependency).IsAssignableFrom(interfaceType)) { registration = registration.InstancePerMatchingLifetimeScope("shell"); } else if (typeof(IUnitOfWorkDependency).IsAssignableFrom(interfaceType)) { registration = registration.InstancePerMatchingLifetimeScope("work"); } else if (typeof(ITransientDependency).IsAssignableFrom(interfaceType)) { registration = registration.InstancePerDependency(); } } if (!typeof(IEventHandler).IsAssignableFrom(item.Type)) continue; var interfaces = item.Type.GetInterfaces(); foreach (var interfaceType in interfaces) { if (interfaceType.GetInterface(typeof(IEventHandler).Name) != null) { registration = registration.Named<IEventHandler>(interfaceType.Name); } } } _shellContainerRegistrationses.Invoke(i => i.Registrations(builder, blueprint), NullLogger.Instance); }); }
public EntityFrameworkDbContextFactory(IServiceTypeHarvester serviceTypeHarvester, IEnumerable<IEntityFrameworkDataServicesProvider> dataServicesProviders, IEnumerable<IMapping> mappings, ShellBlueprint shellBlueprint) { _serviceTypeHarvester = serviceTypeHarvester; _dataServicesProviders = dataServicesProviders; _mappings = mappings; _recordBlueprints = shellBlueprint.GetRecords(); _shellSettings = shellBlueprint.Settings; Logger = NullLogger.Instance; }