Skip to content

Commit

Permalink
Make ApiConfiguration internal
Browse files Browse the repository at this point in the history
  • Loading branch information
chinadragon0515 committed Aug 26, 2016
1 parent 607baf4 commit e088544
Show file tree
Hide file tree
Showing 30 changed files with 188 additions and 645 deletions.
4 changes: 3 additions & 1 deletion src/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
[assembly: SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Scope = "type", Target = "Microsoft.Restier.Core.Submit.ChangeSetValidationException", Justification = "We do not intend to support serialization of this exception yet")]
[assembly: SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.Batch.RestierBatchChangeSetRequestItem.#DisposeResponses(System.Collections.Generic.IEnumerable`1<System.Net.Http.HttpResponseMessage>)")]
[assembly: SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "member", Target = "Microsoft.Restier.Core.ApiBase.#Dispose()", Justification = "Need to do some clean up before the virtual Dispose(disposing) method gets called.")]
[assembly: SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "type", Target = "Microsoft.Restier.Core.ApiContext")]
[assembly: SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "member", Target = "Microsoft.Restier.Core.ApiContext.#Dispose()")]
[assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames", Justification = "These assemblies are delay-signed.")]
[assembly: SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Scope = "member", Target = "Microsoft.Restier.Providers.EntityFramework.ModelProducer.#ProduceModelAsync(Microsoft.Restier.Core.Model.ModelContext,System.Threading.CancellationToken)")]
[assembly: SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Scope = "type", Target = "Microsoft.Restier.Core.Submit.ChangeSetValidationResults")]
Expand Down Expand Up @@ -191,7 +193,7 @@
#endregion

#region CA1812 Uninstantiated internal classes
[assembly: SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Scope = "type", Target = "Microsoft.Restier.Core.ApiBase+ApiHolder")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Scope = "type", Target = "Microsoft.Restier.Core.ApiConfiguration")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Scope = "type", Target = "Microsoft.Restier.Core.ConventionBasedChangeSetItemValidator")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Scope = "type", Target = "Microsoft.Restier.Core.PropertyBag")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Scope = "type", Target = "Microsoft.Restier.Providers.EntityFramework.ModelProducer")]
Expand Down
62 changes: 44 additions & 18 deletions src/Microsoft.Restier.Core/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ namespace Microsoft.Restier.Core
/// </remarks>
public abstract class ApiBase : IDisposable
{
private ApiConfiguration apiConfiguration;
private static ConcurrentDictionary<Type, Action<IServiceCollection>> publisherServicesCallback =
new ConcurrentDictionary<Type, Action<IServiceCollection>>();

private static Action<IServiceCollection> emptyConfig = _ => { };

private ApiContext apiContext;
private IServiceProvider serviceProvider;

Expand Down Expand Up @@ -73,22 +77,6 @@ public ApiContext Context
/// </summary>
public bool IsDisposed { get; private set; }

/// <summary>
/// Gets the API configuration for this API.
/// </summary>
public ApiConfiguration Configuration
{
get
{
if (this.apiConfiguration == null)
{
this.apiConfiguration = serviceProvider.GetService<ApiConfiguration>();
}

return this.apiConfiguration;
}
}

/// <summary>
/// Configure services for this API.
/// </summary>
Expand All @@ -107,11 +95,49 @@ public static IServiceCollection ConfigureApi(Type apiType, IServiceCollection s
.AddConventionBasedServices(apiType);

// This is used to add the publisher's services
ApiConfiguration.GetPublisherServiceCallback(apiType)(services);
GetPublisherServiceCallback(apiType)(services);

return services;
}

/// <summary>
/// Adds a configuration procedure for apiType.
/// This is expected to be called by publisher like WebApi to add services.
/// </summary>
/// <param name="apiType">
/// The Api Type.
/// </param>
/// <param name="configurationCallback">
/// An action that will be called during the configuration of apiType.
/// </param>
[CLSCompliant(false)]
public static void AddPublisherServices(Type apiType, Action<IServiceCollection> configurationCallback)
{
publisherServicesCallback.AddOrUpdate(
apiType,
configurationCallback,
(type, existing) => existing + configurationCallback);
}

/// <summary>
/// Get publisher registering service callback for specified Api.
/// </summary>
/// <param name="apiType">
/// The Api type of which to get the publisher registering service callback.
/// </param>
/// <returns>The service registering callback.</returns>
[CLSCompliant(false)]
public static Action<IServiceCollection> GetPublisherServiceCallback(Type apiType)
{
Action<IServiceCollection> val;
if (publisherServicesCallback.TryGetValue(apiType, out val))
{
return val;
}

return emptyConfig;
}

/// <summary>
/// Performs application-defined tasks associated with
/// freeing, releasing, or resetting unmanaged resources.
Expand Down
272 changes: 0 additions & 272 deletions src/Microsoft.Restier.Core/ApiBaseExtensions.cs

This file was deleted.

Loading

0 comments on commit e088544

Please sign in to comment.