Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Customizing Startup
To create a custom startup class, inherit from Startup.cs. Override the method EnsureAssembliesLoaded() and add the assemblies that are necessary for the implementation. Note: the EnsureAssmebliesLoaded() method validates that the assemblies are loaded in the app domain, and it does not actually load the specific assembly into the app domain. Add the assembly reference for the Owin startup.
The example below includes the enrollment composite, Grand Bend extensions, and sample extensions:
language | c# |
---|
The Ed-Fi ODS / API comes with a set of configurable features that can be enabled or disabled using configuration settings in deployed API. Additional custom features could be implemented by following the steps outlined here:
Step 1. Create a Service
Code Block | ||
---|---|---|
| ||
namespace EdFi.Ods.Services { public class ApiStartupTestService : Api.Startup.StartupITestService { protected override public void EnsureAssembliesLoadedDoSomething() { AssemblyLoader.EnsureLoaded<Marker_EdFi_Ods_Composites_Enrollment>(); AssemblyLoader.EnsureLoaded<Marker_EdFi_Ods_Api_BulkLoad>(); AssemblyLoader.EnsureLoaded<Marker_EdFi_Ods_Extensions_TPDM>(); AssemblyLoader.EnsureLoaded<Marker_EdFi_Ods_Extensions_Sample>(); } } } |
Adding a Feature
Features are new components for the system. It is recommended that a feature be implemented in its own assembly and then referenced into the web project.
Step 1. Create a New Assembly for the Feature
1.a) Install the following packages:
Microsoft.Extensions.Primitives
Autofac.Extensions.Dependency.Injection
1.b) Reference the following projects:
EdFi.Ods.Api
EdFi.Ods.Common
EdFi.Ods.Security
Step 2. Add a New Feature Class
Implement IFeature from EdFi.Ods.Common. Add the Windsor Installer for the feature.Step 2. Add a New Autofac Module Class
2a. Inherit from ConditionalModule in EdFi.Ods.Common.
2b. Override IsSelected method
2c. Override ApplyConfigurationSpecificRegistrations method
Code Block | ||
---|---|---|
| ||
using System.Collections.GenericAutofac; using CastleEdFi.MicroKernelCommon.RegistrationConfiguration; using EdFi.Ods.Common; namespace EdFi.Ods.TestFeature { public class TestFeature : IFeature { public IList<IWindsorInstaller> Installers() => new List<IWindsorInstaller>( { new TestFeatureInstaller() }); public bool IsEnabled() => true; } } |
Note: To set up your feature to be enabled or disabled in the app settings, inherit from ConfigurationBasedFeature and set the feature name, which will be a key for the feature in the configuration file (e.g., <add key="testFeature:featureIsEnabled" value="true"/>
). Add the Windsor Installer for the feature.
Code Block | ||
---|---|---|
| ||
using System.Collections.Generic; using Castle.MicroKernel.Registration; .Configuration; using EdFi.Ods.Common.Container; using EdFi.Ods.Common.ConfigurationTestService; namespace EdFi.Ods.Features.Container.TestFeatureModules { public class TestFeatureTestModule : ConfigurationBasedFeatureConditionalModule { public TestFeatureTestModule(IConfigValueProviderApiSettings configValueProviderapiSettings) : base(configValueProviderapiSettings, nameof(TestModule)) { } protected override string FeatureName => "TestFeature"; public override IList<IWindsorInstaller>bool InstallersIsSelected() => new List<IWindsorInstaller>( { new TestFeatureInstaller() }); } } |
Step 3. Create the Windsor Installer for the Feature
Code Block |
---|
using Castle.MicroKernel.Registration; using Castle.MicroKernel.SubSystems.Configuration; using Castle.Windsor; namespace EdFi.Ods.TestFeature {IsFeatureEnabled(ApiFeature.TestService); public class TestFeatureInstaller : IWindsorInstaller { publicoverride void InstallApplyConfigurationSpecificRegistrations(IWindsorContainer container, IConfigurationStore storeContainerBuilder builder) { // TODO add components to register. } } } |
Step
43.
Modify WindsorContainerBuilderAdd the feature to the container builder.
Add Configuration Setting in appsettings.json in EdFi.Ods.WebApi Project
Code Block | ||
---|---|---|
| ||
{ ... "Features": [ { Component.For<IFeature>().ImplementedBy<ChangeQueriesFeature>()"Name": "TestService", "IsEnabled": true Component.For<IFeature>().ImplementedBy<CompositesFeature>(), } Component.For<IFeature>().ImplementedBy<OpenApiMetadataFeature>(), Component.For<IFeature>().ImplementedBy<ProfilesFeature>(), Component.For<IFeature>().ImplementedBy<ExtensionsFeature>(), Component.For<IFeature>().ImplementedBy<IdentityFeature>(), Component.For<IFeature>().ImplementedBy<BulkApiFeature>(), Component.For<IFeature>().ImplementedBy<TestFeature.TestFeature>(), Component.For<IFeatureProvider>().ImplementedBy<FeatureProvider>()); } |
Miscellaneous Notes
When building a feature that requires a controller, implement the following interfaces: IRouteConfiguration and IOpenApiMetadataRouteConfiguration for setting up the routes, plus IOpenApiContentProvider for defining OpenApiMetadata. These interfaces are specific to using the feature within the ODS / API and is necessary for the controller. These interfaces are then registered within the installer.
]
...
} |