Skip to content

Commit

Permalink
More changes for test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chinadragon0515 committed Aug 23, 2016
1 parent 9d055f2 commit 673d520
Show file tree
Hide file tree
Showing 43 changed files with 524 additions and 747 deletions.
45 changes: 17 additions & 28 deletions src/Microsoft.Restier.Core/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public ApiContext Context
{
apiScope.Api = this;
}

ApiConfiguratorAttributes.ApplyInitialization(
this.GetType(), this, this.apiContext);
}

return this.apiContext;
Expand All @@ -63,9 +60,9 @@ public ApiContext Context
public bool IsDisposed { get; private set; }

/// <summary>
/// Gets the API configuration for this API.
/// Gets or sets the API configuration for this API.
/// </summary>
protected ApiConfiguration Configuration
public ApiConfiguration Configuration
{
get
{
Expand All @@ -74,17 +71,18 @@ protected ApiConfiguration Configuration
return this.apiConfiguration;
}

return this.apiConfiguration = Configurations.GetOrAdd(
this.GetType(),
apiType =>
{
IServiceCollection services = new ServiceCollection();
services = this.ConfigureApi(services);
Configurations.TryGetValue(this.GetType(), out this.apiConfiguration);
return this.apiConfiguration;
}

var configuration = this.CreateApiConfiguration(services);
ApiConfiguratorAttributes.ApplyConfiguration(apiType, configuration);
return configuration;
});
set
{
this.apiConfiguration = value;
bool isSuccess = Configurations.TryAdd(GetType(), apiConfiguration);
if (isSuccess)
{
UpdateApiConfiguration(this.apiConfiguration);
}
}
}

Expand All @@ -103,9 +101,6 @@ public void Dispose()

if (this.apiContext != null)
{
ApiConfiguratorAttributes.ApplyDisposal(
this.GetType(), this, this.apiContext);

this.apiContext.DisposeScope();
this.apiContext = null;
}
Expand All @@ -121,13 +116,12 @@ public void Dispose()
/// </param>
/// <returns>The <see cref="IServiceCollection"/>.</returns>
[CLSCompliant(false)]
protected virtual IServiceCollection ConfigureApi(IServiceCollection services)
public virtual IServiceCollection ConfigureApi(IServiceCollection services)
{
Type apiType = this.GetType();

// Add core and convention's services
services = services.AddCoreServices(apiType)
.AddAttributeServices(apiType)
.AddConventionBasedServices(apiType);

// This is used to add the publisher's services
Expand All @@ -137,18 +131,13 @@ protected virtual IServiceCollection ConfigureApi(IServiceCollection services)
}

/// <summary>
/// Creates the API configuration for this API.
/// Descendants may override to use a customized DI container, or further configure the built
/// Allow user to update the ApiConfiguration
/// <see cref="ApiConfiguration"/>.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> containing API service registrations.</param>
/// <returns>
/// An <see cref="ApiConfiguration"/> with which to create the API configuration for this API.
/// </returns>
/// <param name="configuration">The <see cref="ApiConfiguration"/> for the Api instance.</param>
[CLSCompliant(false)]
protected virtual ApiConfiguration CreateApiConfiguration(IServiceCollection services)
protected virtual void UpdateApiConfiguration(ApiConfiguration configuration)
{
return services.BuildApiConfiguration();
}

/// <summary>
Expand Down
87 changes: 0 additions & 87 deletions src/Microsoft.Restier.Core/ApiConfiguratorAttribute.cs

This file was deleted.

137 changes: 0 additions & 137 deletions src/Microsoft.Restier.Core/ApiConfiguratorAttributes.cs

This file was deleted.

5 changes: 2 additions & 3 deletions src/Microsoft.Restier.Core/ApiContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public static async Task<IEdmModel> GetModelAsync(

try
{
var buildContext = new ModelContext(context);
var buildContext = new ModelContext();
buildContext.ServiceProvider = context.ServiceProvider;
var model = await builder.GetModelAsync(buildContext, cancellationToken);
source.SetResult(model);
return model;
Expand Down Expand Up @@ -461,8 +462,6 @@ public static async Task<SubmitResult> SubmitAsync(
Ensure.NotNull(context, "context");

var submitContext = new SubmitContext(context, changeSet);
var model = await context.GetModelAsync(cancellationToken);
submitContext.Model = model;
return await DefaultSubmitHandler.SubmitAsync(submitContext, cancellationToken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Task<bool> AuthorizeAsync(
object target = null;
if (!method.IsStatic)
{
target = context.GetApiService<ApiBase>();
target = context.ImplementInstance;
if (target == null ||
!this.targetType.IsInstanceOfType(target))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private Task InvokeProcessorMethodAsync(
object target = null;
if (!method.IsStatic)
{
target = context.GetApiService<ApiBase>();
target = context.ImplementInstance;
if (target == null ||
!this.targetType.IsInstanceOfType(target))
{
Expand Down
12 changes: 12 additions & 0 deletions src/Microsoft.Restier.Core/InvocationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ namespace Microsoft.Restier.Core
/// </remarks>
public class InvocationContext
{
/// <summary>
/// Initializes a new instance of the <see cref="InvocationContext" /> class.
/// </summary>
public InvocationContext()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="InvocationContext" /> class.
/// </summary>
Expand All @@ -32,5 +39,10 @@ public InvocationContext(ApiContext apiContext)
/// Gets the API context.
/// </summary>
public ApiContext ApiContext { get; private set; }

/// <summary>
/// Gets or sets the <see cref="IServiceProvider"/> which contains all services of this scope.
/// </summary>
public IServiceProvider ServiceProvider { get; set; }
}
}
Loading

0 comments on commit 673d520

Please sign in to comment.