Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove UnityFactory #280

Open
wants to merge 47 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bc14401
Updated NewPlatform.Flexberry.ORM Up to 7.2.0-alpha01
Anisimova2020 Apr 6, 2023
bf342f7
Fast fixes for project building after ORM update
Anisimova2020 Apr 6, 2023
89510de
Fast fixes of unity config after ORM update
Anisimova2020 Apr 6, 2023
6fc1776
Fast fixes of tests after ORM update
Anisimova2020 Apr 10, 2023
c1f06c8
Remove not yet released code
turbcool Apr 28, 2023
b9f585f
Remove UnityFactory from DataObjectEdmModel
turbcool Apr 28, 2023
42906c1
DataObjectEdmModel использует IServiceProvider
turbcool May 19, 2023
c5b8a4c
Убираем UnityFactory из тестов
turbcool May 19, 2023
f229dfa
DataObjectEdmModel uses UnityContainer
turbcool May 19, 2023
806d037
Merge with develop branch
Anisimova2020 May 23, 2023
fd718df
Updated packages to versions changed to DI
Anisimova2020 May 25, 2023
e562f06
Merge branch 'feature-239-use-proper-di' of https://github.com/Flexbe…
Anisimova2020 May 25, 2023
921a215
Rollback
May 30, 2023
49e07cc
Merge pull request #282 from torres6093/feature-239-use-proper-di-rol…
Anisimova2020 May 30, 2023
1226aeb
Register for DefaultDataObjectEdmModelBuilder
May 31, 2023
c6783bc
New class for DataObjectEdmModel dependencies
May 31, 2023
900bf76
Removed RegisterFactory
May 31, 2023
37934d9
Code correction and comments
Jun 1, 2023
243d5c1
Commented new class
Jun 1, 2023
b83e09a
Merge pull request #283 from torres6093/feature-231939-remove-unityfa…
Anisimova2020 Jun 1, 2023
0c93a4a
Added registration for DataObjectEdmModelDependencies (this will be m…
Anisimova2020 Jun 1, 2023
00e4193
Trying to get connection string value
Jun 1, 2023
5a90da9
Fixed extra Unity Containers creation
Anisimova2020 Jun 2, 2023
98c2112
Added proper business server provider initialisation
Anisimova2020 Jun 2, 2023
4d087c2
Code cleanup
Jun 2, 2023
d23e1b5
App.config rollback
Jun 2, 2023
c6aa544
Fix after code review
Jun 2, 2023
5c250f1
Comment for static field
Jun 5, 2023
068e4be
Merge pull request #285 from torres6093/feature-fix-start
Anisimova2020 Jun 5, 2023
f01edf8
Added NuGet.config
Anisimova2020 Jun 5, 2023
d7f7063
Try to fix server tests
Anisimova2020 Jun 5, 2023
4b70a04
Try to fix github build
Anisimova2020 Jun 5, 2023
16ca471
Try to fix github build
Anisimova2020 Jun 5, 2023
3ade9b8
Try to fix github build
Anisimova2020 Jun 5, 2023
9109e48
Try to fix github build
Anisimova2020 Jun 5, 2023
3eb082d
Repair of github build
Anisimova2020 Jun 5, 2023
64c11f4
Fixed error on tests on net7 for github
Anisimova2020 Jun 5, 2023
ba5d6f8
Changed nuget source for github actions
Anisimova2020 Jun 5, 2023
d773553
Fixed tests for net4.5
Anisimova2020 Jun 6, 2023
189ae0e
Moving of serviceprovider creation
Anisimova2020 Jun 6, 2023
b2a4b10
Remove nuget.config
Anisimova2020 Jun 6, 2023
2fcfef0
Updated version of NewPlatform.Flexberry.ORM.ODataService up to 7.2.0…
Anisimova2020 Jun 6, 2023
8fec6f6
Merge with develop
Anisimova2020 Oct 11, 2023
934450a
Merge branch 'develop' of https://github.com/Flexberry/NewPlatform.Fl…
hvostya Mar 28, 2024
34710f5
Генерация файла testhost.dll.config
turbcool Mar 29, 2024
40608e0
Передача UnityContainer в тесты
Mar 29, 2024
5ef36ba
Рефакторинг использования unityContainer в тестах
Apr 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.2.0-alpha02" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NewPlatform.Flexberry.LockService" Version="3.0.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.2.0-alpha02" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
10 changes: 5 additions & 5 deletions NewPlatform.Flexberry.ORM.ODataService.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@
<dependency id="Microsoft.OData.Edm" version="7.10.0" />
<dependency id="Microsoft.Spatial" version="7.10.0" />
<dependency id="NewPlatform.Flexberry.LockService" version="3.0.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.1.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.2.0-alpha02" />
<dependency id="Newtonsoft.Json" version="13.0.1" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="NewPlatform.Flexberry.AspNetCore.OData" version="7.6.2" />
<dependency id="NewPlatform.Flexberry.LockService" version="3.0.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.1.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.2.0-alpha02" />
<dependency id="Newtonsoft.Json" version="13.0.1" />
</group>
<group targetFramework=".NETCoreApp3.1">
<dependency id="NewPlatform.Flexberry.AspNetCore.OData" version="7.6.2" />
<dependency id="NewPlatform.Flexberry.LockService" version="3.0.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.1.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.2.0-alpha02" />
<dependency id="Newtonsoft.Json" version="13.0.1" />
</group>
<group targetFramework=".NET6.0">
<dependency id="NewPlatform.Flexberry.AspNetCore.OData" version="7.6.2" />
<dependency id="NewPlatform.Flexberry.LockService" version="3.0.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.1.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.2.0-alpha02" />
<dependency id="Newtonsoft.Json" version="13.0.1" />
</group>
<group targetFramework=".NET7.0">
<dependency id="NewPlatform.Flexberry.AspNetCore.OData" version="7.6.2" />
<dependency id="NewPlatform.Flexberry.LockService" version="3.0.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.1.0" />
<dependency id="NewPlatform.Flexberry.ORM" version="7.2.0-alpha02" />
<dependency id="Newtonsoft.Json" version="13.0.1" />
</group>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace NewPlatform.Flexberry.ORM.ODataService
using System.Web.Http.Routing;
using ICSSoft.STORMNET;
using ICSSoft.STORMNET.Business;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Routing;
using Microsoft.Extensions.DependencyInjection;
using NewPlatform.Flexberry.ORM.ODataService.Batch;
using NewPlatform.Flexberry.ORM.ODataService.Controllers;
using NewPlatform.Flexberry.ORM.ODataService.Extensions;
Expand Down Expand Up @@ -55,71 +57,26 @@ public IHttpController Create(HttpRequestMessage request, HttpControllerDescript
/// <returns>An <see cref="DataObjectController" /> object for specified arguments.</returns>
protected virtual DataObjectController CreateDataObjectController(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
{
IDataService dataService = GetDataService(request, controllerDescriptor, controllerType);

IDataObjectFileAccessor fileAccessor = GetDataObjectFileAccessor(request, controllerDescriptor, controllerType);

DataObjectCache dataObjectCache = GetDataObjectCache(request, controllerDescriptor, controllerType);
//TODO: поменять DependencyResolver на IServiceProvider
IDependencyResolver dependencyResolver = request.GetConfiguration().DependencyResolver;
IDataService dataService = (IDataService)dependencyResolver.GetService(typeof(IDataService));
IDataObjectFileAccessor fileAccessor = (IDataObjectFileAccessor)dependencyResolver.GetService(typeof(IDataObjectFileAccessor));

DataObjectCache dataObjectCache = GetDataObjectCache(request);
ManagementToken token = (request.GetRouteData().Route as ODataRoute).GetManagementToken();

DataObjectController controller = new DataObjectController(dataService, fileAccessor, dataObjectCache, token.Model, token.Events, token.Functions);
controller.OfflineManager = GetOfflineManager(request, controllerDescriptor, controllerType) ?? controller.OfflineManager;

return controller;
}

/// <summary>
/// Gets the instance of <see cref="IDataService" /> using current <see cref="IDependencyScope"/> and <see cref="IHttpRoute"/>.
/// </summary>
/// <param name="request">The message request.</param>
/// <param name="controllerDescriptor">The HTTP controller descriptor.</param>
/// <param name="controllerType">The type of the controller.</param>
/// <returns>Gets the instance of <see cref="IDataService" /> for specified arguments.</returns>
/// <remarks>Extracts object from configurated <see cref="IDependencyResolver" />.</remarks>
protected virtual IDataService GetDataService(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
{
IDependencyResolver dependencyResolver = request.GetConfiguration().DependencyResolver;
IDataService dataService = (IDataService)dependencyResolver.GetService(typeof(IDataService));

if (dataService == null)
{
throw new InvalidOperationException("IDataService is not registered in the dependency scope.");
}

return dataService;
}

/// <summary>
/// Gets the instance of <see cref="IDataObjectFileAccessor" /> using current <see cref="IDependencyScope"/> and <see cref="IHttpRoute"/>.
/// Gets the instance of <see cref="DataObjectCache" /> from <see cref="HttpRequestMessage"/> />.
/// </summary>
/// <param name="request">The message request.</param>
/// <param name="controllerDescriptor">The HTTP controller descriptor.</param>
/// <param name="controllerType">The type of the controller.</param>
/// <returns>Gets the instance of <see cref="IDataObjectFileAccessor" /> for specified arguments.</returns>
/// <remarks>Extracts object from configurated <see cref="IDependencyResolver" />.</remarks>
protected virtual IDataObjectFileAccessor GetDataObjectFileAccessor(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
{
IDependencyResolver dependencyResolver = request.GetConfiguration().DependencyResolver;
IDataObjectFileAccessor fileAccessor = (IDataObjectFileAccessor)dependencyResolver.GetService(typeof(IDataObjectFileAccessor));

if (fileAccessor == null)
{
throw new InvalidOperationException("IDataObjectFileAccessor is not registered in the dependency scope.");
}

return fileAccessor;
}

/// <summary>
/// Gets the instance of <see cref="DataObjectCache" /> using current <see cref="IDependencyScope"/> and <see cref="IHttpRoute"/>.
/// </summary>
/// <param name="request">The message request.</param>
/// <param name="controllerDescriptor">The HTTP controller descriptor.</param>
/// <param name="controllerType">The type of the controller.</param>
/// <returns>Gets the instance of <see cref="DataObjectCache" /> for specified arguments.</returns>
/// <remarks>Extracts object from request properties for batch requests.</remarks>
protected virtual DataObjectCache GetDataObjectCache(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
protected virtual DataObjectCache GetDataObjectCache(HttpRequestMessage request)
{
DataObjectCache dataObjectCache = null;
if (request.Properties.ContainsKey(PostPatchHandler.PropertyKeyBatchRequest) && request.Properties.ContainsKey(DataObjectODataBatchHandler.DataObjectCachePropertyKey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static ManagementToken MapDataObjectRoute(

// Model.
DataObjectEdmModel model = builder.Build();
config.DependencyResolver.GetService(typeof(DataObjectEdmModel));

// DataService for batch requests support.
IDataService dataService = (IDataService)config.DependencyResolver.GetService(typeof(IDataService));
Expand Down
25 changes: 10 additions & 15 deletions NewPlatform.Flexberry.ORM.ODataService/Model/DataObjectEdmModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using ICSSoft.Services;
using ICSSoft.STORMNET;

using Microsoft.AspNet.OData;
using Microsoft.AspNet.OData.Formatter;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OData.Edm;
using Microsoft.Spatial;

using NewPlatform.Flexberry.ORM.ODataService.Functions;

using Unity;

using Action = Functions.Action;

/// <summary>
Expand Down Expand Up @@ -89,10 +85,9 @@ public class DataObjectEdmModel : EdmModel
private readonly IDictionary<Type, EdmEntitySet> _registeredEntitySets = new Dictionary<Type, EdmEntitySet>();
private readonly IDictionary<Type, IList<Type>> _typeHierarchy = new Dictionary<Type, IList<Type>>();

public DataObjectEdmModel(DataObjectEdmMetadata metadata, IDataObjectEdmModelBuilder edmModelBuilder = null)
public DataObjectEdmModel(DataObjectEdmMetadata metadata, IDataObjectEdmModelBuilder edmModelBuilder = null, IUnityContainer container = null)
{
EdmModelBuilder = edmModelBuilder;
var container = UnityFactory.GetContainer();
if (container != null)
{
if (container.IsRegistered<IExportService>("Export"))
Expand Down Expand Up @@ -738,14 +733,14 @@ private string GetEntityTypeNamespace(Type type)
{
var name = type.Namespace;
if (type != typeof(DataObject) && EdmModelBuilder != null && EdmModelBuilder.EntityTypeNamespaceBuilder != null)
name = EdmModelBuilder.EntityTypeNamespaceBuilder(type);
// There are extra checks on MS libraries that lead to exceptions if name is empty or null.
if (name == string.Empty)
{
return "____";
}
name = EdmModelBuilder.EntityTypeNamespaceBuilder(type);

// There are extra checks on MS libraries that lead to exceptions if name is empty or null.
if (name == string.Empty)
{
return "____";
}

return name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ICSSoft.STORMNET.KeyGen;

using Microsoft.OData.Edm;
using Unity;

/// <summary>
/// Default implementation of <see cref="IDataObjectEdmModelBuilder"/>.
Expand All @@ -32,6 +33,11 @@ public class DefaultDataObjectEdmModelBuilder : IDataObjectEdmModelBuilder
/// </summary>
private readonly PseudoDetailDefinitions _pseudoDetailDefinitions;

/// <summary>
/// Service provider for resolving DataObjectEdmModel.
/// </summary>
private readonly IUnityContainer _container;

/// <summary>
/// Additional mapping of CLR type to edm primitive type. When it's required on the application side.
/// </summary>
Expand Down Expand Up @@ -75,16 +81,19 @@ public class DefaultDataObjectEdmModelBuilder : IDataObjectEdmModelBuilder
/// Initializes a new instance of the <see cref="DefaultDataObjectEdmModelBuilder"/> class.
/// </summary>
/// <param name="searchAssemblies">The list of assemblies for searching types to expose.</param>
/// <param name="container">Unity container for resolving dependencies.</param>
/// <param name="useNamespaceInEntitySetName">Is need to add the whole type namespace for EDM entity set.</param>
/// <param name="pseudoDetailDefinitions">A collection of pseudodetail links.</param>
/// <param name="additionalMapping">Additional mapping of CLR type to edm primitive type.</param>
public DefaultDataObjectEdmModelBuilder(
IEnumerable<Assembly> searchAssemblies,
IUnityContainer container = null,
bool useNamespaceInEntitySetName = true,
PseudoDetailDefinitions pseudoDetailDefinitions = null,
Dictionary<Type, IEdmPrimitiveType> additionalMapping = null)
{
_searchAssemblies = searchAssemblies ?? throw new ArgumentNullException(nameof(searchAssemblies), "Contract assertion not met: searchAssemblies != null");
_container = container;
_useNamespaceInEntitySetName = useNamespaceInEntitySetName;
_pseudoDetailDefinitions = pseudoDetailDefinitions ?? new PseudoDetailDefinitions();

Expand All @@ -110,7 +119,7 @@ public DataObjectEdmModel Build()

var typeFilter = TypeFilter ?? (t => true);

foreach (Assembly assembly in _searchAssemblies)
foreach (Assembly assembly in _searchAssemblies.Where(x => !x.FullName.Contains("UserSettingsService")))
Anisimova2020 marked this conversation as resolved.
Show resolved Hide resolved
{
IEnumerable<Type> dataObjectTypes = assembly
.GetTypes()
Expand Down Expand Up @@ -143,7 +152,7 @@ public DataObjectEdmModel Build()
}
}

return new DataObjectEdmModel(meta, this);
return new DataObjectEdmModel(meta, this, _container);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NewPlatform.Flexberry.LockService" Version="3.0.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.2.0-alpha02" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
using System.Collections.Generic;
using System.Linq;

using ICSSoft.Services;
using ICSSoft.STORMNET;

using Microsoft.AspNet.OData.Query;

using ICSSoft.STORMNET;
using Microsoft.AspNet.OData.Query;
using NewPlatform.Flexberry.ORM.CurrentUserService;
using NewPlatform.Flexberry.Services;

public class DefaultOfflineManager : BaseOfflineManager
{
private readonly ILockService _lockService;

private readonly CurrentUserService.IUser _currentUser;
private readonly ICurrentUser _currentUser;

public DefaultOfflineManager(ILockService lockService, CurrentUserService.IUser currentUser)
public DefaultOfflineManager(ILockService lockService, ICurrentUser currentUser)
{
_lockService = lockService ?? throw new ArgumentNullException(nameof(lockService), "Contract assertion not met: lockService != null");
_currentUser = currentUser ?? throw new ArgumentNullException(nameof(currentUser), "Contract assertion not met: currentUser != null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using ICSSoft.STORMNET;
using ICSSoft.STORMNET.Business.Audit;
using NewPlatform.Flexberry.ORM.CurrentUserService;

/// <summary>
/// Implementation of <see cref="AuditService"/> for offline audit mode.
Expand All @@ -12,6 +13,17 @@
/// <seealso cref="AuditService" />
public class OfflineAuditService : AuditService
{
/// <summary>
/// Initializes a new instance of the <see cref="OfflineAuditService"/> class.
/// </summary>
/// <param name="currentUser">
/// Service for approach to data of current user.
/// </param>
public OfflineAuditService(ICurrentUser currentUser)
: base(currentUser)
{
}

/// <summary>
/// Adds audit information for specified new data object.
/// Does nothing in order to preserve data at <see cref="IDataObjectWithAuditFields"/> fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.2.0-alpha02" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM.MSSQLDataService" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM.OracleDataService" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM.PostgresDataService" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.2.0-alpha02" />
<PackageReference Include="NewPlatform.Flexberry.ORM.MSSQLDataService" Version="7.2.0-alpha02" />
<PackageReference Include="NewPlatform.Flexberry.ORM.OracleDataService" Version="7.2.0-alpha02" />
<PackageReference Include="NewPlatform.Flexberry.ORM.PostgresDataService" Version="7.2.0-alpha02" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading