Skip to content

Commit

Permalink
Remove restier container and use WAO container
Browse files Browse the repository at this point in the history
  • Loading branch information
chinadragon0515 committed Aug 25, 2016
1 parent 32cf19d commit 607baf4
Show file tree
Hide file tree
Showing 60 changed files with 493 additions and 595 deletions.
37 changes: 12 additions & 25 deletions src/Microsoft.Restier.Core/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ namespace Microsoft.Restier.Core
/// </remarks>
public abstract class ApiBase : IDisposable
{
private static readonly ConcurrentDictionary<Type, ApiConfiguration> Configurations =
new ConcurrentDictionary<Type, ApiConfiguration>();

private ApiConfiguration apiConfiguration;
private ApiContext apiContext;
private IServiceProvider serviceProvider;

/// <summary>
/// Initializes a new instance of the <see cref="ApiBase" /> class.
/// </summary>
/// <param name="serviceProvider">
/// An <see cref="IServiceProvider"/> containing all services of this <see cref="ApiConfiguration"/>.
/// </param>
protected ApiBase(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}

/// <summary>
/// Gets the <see cref="IServiceProvider"/> which contains all services of this <see cref="ApiConfiguration"/>.
/// </summary>
Expand All @@ -37,12 +45,6 @@ public IServiceProvider ServiceProvider
{
return serviceProvider;
}

set
{
// TODO use set but not in constructor as need to update lots of test cases
this.serviceProvider = value;
}
}

/// <summary>
Expand Down Expand Up @@ -72,7 +74,7 @@ public ApiContext Context
public bool IsDisposed { get; private set; }

/// <summary>
/// Gets or sets the API configuration for this API.
/// Gets the API configuration for this API.
/// </summary>
public ApiConfiguration Configuration
{
Expand All @@ -85,13 +87,6 @@ public ApiConfiguration Configuration

return this.apiConfiguration;
}

set
{
// TODO keep now as lots of test cases need to update
this.apiConfiguration = value;
Configurations.TryAdd(GetType(), apiConfiguration);
}
}

/// <summary>
Expand Down Expand Up @@ -137,13 +132,5 @@ public void Dispose()

GC.SuppressFinalize(this);
}

// Registered as a scoped service so that IApi and ApiContext could be exposed as scoped service.
// If a descendant class wants to expose these 2 services in another way, it must ensure they could be
// resolved after CreateApiContext call.
internal class ApiHolder
{
public ApiBase Api { get; set; }
}
}
}
21 changes: 0 additions & 21 deletions src/Microsoft.Restier.Core/ApiConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,8 @@ public class ApiConfiguration

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

private IServiceProvider serviceProvider;

private Task<IEdmModel> modelTask;

/// <summary>
/// Initializes a new instance of the <see cref="ApiConfiguration" /> class.
/// </summary>
/// <param name="serviceProvider">
/// An <see cref="IServiceProvider"/> containing all services of this <see cref="ApiConfiguration"/>.
/// </param>
public ApiConfiguration(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}

/// <summary>
/// Gets the <see cref="IServiceProvider"/> which contains all services of this <see cref="ApiConfiguration"/>.
/// </summary>
internal IServiceProvider ServiceProvider
{
get { return serviceProvider; }
}

internal IEdmModel Model { get; private set; }

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

This file was deleted.

6 changes: 3 additions & 3 deletions src/Microsoft.Restier.Core/ApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class ApiContext
/// <summary>
/// Initializes a new instance of the <see cref="ApiContext" /> class.
/// </summary>
/// <param name="configuration">
/// An API configuration.
/// </param>
/// <param name="provider">
/// The service provider.
/// </param>
/// <param name="configuration">
/// An API configuration.
/// </param>
public ApiContext(IServiceProvider provider, ApiConfiguration configuration)
{
Ensure.NotNull(configuration, "configuration");
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.Restier.Core/Microsoft.Restier.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<HintPath>..\..\packages\Microsoft.OData.Core.7.0.0-beta\lib\portable-net45+win8+wpa81\Microsoft.OData.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.OData.Edm, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.OData.Edm.7.0.0-beta\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll</HintPath>
<HintPath>..\..\packages\Microsoft.OData.Edm.7.0.0\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down Expand Up @@ -73,7 +73,6 @@
<Compile Include="ApiBaseExtensions.cs" />
<Compile Include="ApiBase.cs" />
<Compile Include="ApiConfiguration.cs" />
<Compile Include="ApiConfigurationExtensions.cs" />
<Compile Include="ApiContext.cs" />
<Compile Include="ApiContextExtensions.cs" />
<Compile Include="DataSourceStub.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Restier.Core/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<packages>
<package id="Microsoft.Extensions.DependencyInjection" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.OData.Edm" version="7.0.0-beta" targetFramework="net45" />
<package id="Microsoft.OData.Edm" version="7.0.0" targetFramework="net45" />
<package id="System.Collections" version="4.0.11" targetFramework="net45" />
<package id="System.Collections.Concurrent" version="4.0.12" targetFramework="net45" />
<package id="System.ComponentModel" version="4.0.1" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ namespace Microsoft.Restier.Providers.EntityFramework
#endif
public class EntityFrameworkApi<T> : ApiBase where T : DbContext
{
/// <summary>
/// Initializes a new instance of the <see cref="EntityFrameworkApi{T}" /> class.
/// </summary>
/// <param name="serviceProvider">
/// An <see cref="IServiceProvider"/> containing all services of this <see cref="ApiConfiguration"/>.
/// </param>
public EntityFrameworkApi(IServiceProvider serviceProvider) : base(serviceProvider)
{
}

/// <summary>
/// Gets the underlying DbContext for this API.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.OData.Edm, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.OData.Edm.7.0.0-beta\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll</HintPath>
<HintPath>..\..\packages\Microsoft.OData.Edm.7.0.0\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Spatial, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Spatial.7.0.0-beta\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll</HintPath>
<HintPath>..\..\packages\Microsoft.Spatial.7.0.0\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.OData.Edm" version="7.0.0-beta" targetFramework="net45" />
<package id="Microsoft.Spatial" version="7.0.0-beta" targetFramework="net45" />
<package id="Microsoft.OData.Edm" version="7.0.0" targetFramework="net45" />
<package id="Microsoft.Spatial" version="7.0.0" targetFramework="net45" />
<package id="System.ComponentModel" version="4.0.1" targetFramework="net45" />
<package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net45" />
<package id="System.Globalization" version="4.0.11" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Threading;
using System.Threading.Tasks;
using System.Web.OData.Batch;
using System.Web.OData.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Restier.Core;
using Microsoft.Restier.Core.Submit;

Expand All @@ -17,19 +19,13 @@ namespace Microsoft.Restier.Publishers.OData.Batch
/// </summary>
public class RestierBatchChangeSetRequestItem : ChangeSetRequestItem
{
private Func<ApiBase> apiFactory;

/// <summary>
/// Initializes a new instance of the <see cref="RestierBatchChangeSetRequestItem" /> class.
/// </summary>
/// <param name="requests">The request messages.</param>
/// <param name="apiFactory">Gets or sets the callback to create API.</param>
public RestierBatchChangeSetRequestItem(IEnumerable<HttpRequestMessage> requests, Func<ApiBase> apiFactory)
public RestierBatchChangeSetRequestItem(IEnumerable<HttpRequestMessage> requests)
: base(requests)
{
Ensure.NotNull(apiFactory, "apiFactory");

this.apiFactory = apiFactory;
}

/// <summary>
Expand Down Expand Up @@ -89,9 +85,10 @@ public override async Task<ODataBatchResponseItem> SendRequestAsync(
return new ChangeSetResponseItem(responses);
}

internal async Task SubmitChangeSet(ChangeSet changeSet)
internal async Task SubmitChangeSet(HttpRequestMessage request, ChangeSet changeSet)
{
using (var api = this.apiFactory())
var requestContainer = request.GetRequestContainer();
using (var api = requestContainer.GetService<ApiBase>())
{
SubmitResult submitResults = await api.SubmitAsync(changeSet);
}
Expand Down
Loading

0 comments on commit 607baf4

Please sign in to comment.