-
Notifications
You must be signed in to change notification settings - Fork 12
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
Register unity without config file #286
base: feature-239-use-proper-di
Are you sure you want to change the base?
Register unity without config file #286
Conversation
@@ -66,6 +70,56 @@ public virtual void ConfigureContainer(IUnityContainer unityContainer) | |||
unityContainer.RegisterInstance(dataService); | |||
unityContainer.RegisterInstance<ILockService>(new LockService(dataService)); | |||
unityContainer.RegisterInstance<ISecurityManager>(new EmptySecurityManager()); | |||
|
|||
unityContainer.RegisterType<IAuditService, AuditService>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Посмотрела ORM. Там конструктору AuditService требуется ICurrentUser. Давай сразу это понятно пропишем по аналогии с MSSQLDataService.
Думаю, нужно иные классы по аналогии перепроверить.
Вот ветка: https://github.com/Flexberry/NewPlatform.Flexberry.ORM/tree/feature-239-use-proper-di.
Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/App_Start/UnityWebApiActivator.cs
Outdated
Show resolved
Hide resolved
Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs
Outdated
Show resolved
Hide resolved
Tests/NewPlatform.Flexberry.ORM.ODataService.Tests/BaseODataServiceIntegratedTest.cs
Outdated
Show resolved
Hide resolved
@@ -1,7 +1,7 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<configuration> | |||
<configSections> | |||
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration" /> | |||
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно стараться избегать несодержательные правки.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
namespace NewPlatform.Flexberry.ORM.ODataService.Tests | ||
{ | ||
using System; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для чего здесь юзинги добавлены?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
using Unity.Injection; | ||
|
||
/// <summary> | ||
/// This static class is designed to register dependencies in the Unity container. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мне кажется, что в комментариях нужно сделать акцент, что это просто вспомогательный класс для тестов.
Также добавь в комментарии, что при удалении UnityConfigResolver для версии под дотнет 4.5 нужно определить нужность данного класса (пока что перерегистрировать нужно именно из-за него). Также упоминание "UnityConfigResolver" требуется, чтобы при удалении этого класса поиском наткнулись на это примечание.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
unityContainer.RegisterType<IAuditService, AuditService>( | ||
new InjectionConstructor(unityContainer.Resolve<ICurrentUser>())); | ||
|
||
unityContainer.RegisterSingleton<IExportService, ExportExcelODataService>("Export"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Разве это не регистрация изначально закомментированного кода?
"
"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
||
unityContainer.RegisterSingleton<IExportService, ExportExcelODataService>("Export"); | ||
unityContainer.RegisterSingleton<IODataExportService, ExportExcel>(); | ||
unityContainer.RegisterSingleton<ISpreadsheetCustomizer, SpreadsheetCustomizer>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Аналогично.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
/// Method for base dependencies registration into Unity container. | ||
/// </summary> | ||
/// <param name="unityContainer">Unity container.</param> | ||
public static void Registration(IUnityContainer unityContainer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пожалуй, стоит ещё отметить, какой код можно сделать только кодом, а какой и кодом и конфигом. Например, сначала тот, что и там и там, отметив комментарием. А потом тот, что только кодом теперь.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
<dependency /> | ||
</param> | ||
<param name="businessServerProvider" type="ICSSoft.STORMNET.Business.Interfaces.IBusinessServerProvider, ICSSoft.STORMNET.Business"> | ||
<dependency /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мне вот эта регистрация очень интересна, проходит ли корректно. Можешь убрать все регистрации в коде, потом сделать получение dataServiceForAuditAgentManagerAdapter. Мне очень интересно, как оно разрешает конструктор "BusinessServerProvider(IServiceProvider serviceProvider)". Нужно под дебагом посмотреть, инициализируется ли приватное свойство "serviceProvider".
Дело в том, что регистрация "unityContainer.RegisterFactory(new Func<IUnityContainer, object>(o => new BusinessServerProvider(new UnityServiceProvider(o))), FactoryLifetime.Singleton);" была наверчена от того, что конфиг в теории не должен был дать это нормально разрешить. Соответственно, если это работает, то круто, об этом нужно сообщить мне, я включу в свои документы. Если это не работает, а срабатывало только от того, что юнити так сильно не проверяло, то нужно оставить в конфиге только работающее.
Либо возможно работает, потому что сейчас в коде фабрика дорегистрируется IBusinessServerProvider как фабрика. Это тоже хороший вариант, о котором нужно мне сказать.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
using Unity.Injection; | ||
using Xunit; | ||
|
||
public class CheckLoadConfigurationTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужны комментарии к классу тестов.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
using System.Collections; | ||
using System.Configuration; | ||
using System.Globalization; | ||
using System.Linq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
После System-юзингов желательно пустую строчку.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
{ | ||
throw new Exception("Unity.IUnityContainer is not defined"); | ||
} | ||
IUnityContainer localContainer = _unityContainer ?? new UnityContainer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Стоит добавить комментарий, в каком случае может потребоваться создавать контейнер прямо здесь.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
using NewPlatform.Flexberry.ORM.ODataService.Extensions; | ||
using NewPlatform.Flexberry.ORM.ODataService.Files; | ||
using NewPlatform.Flexberry.ORM.ODataService.Model; | ||
using NewPlatform.Flexberry.ORM.ODataService.Tests; | ||
using NewPlatform.Flexberry.ORM.ODataService.WebApi.Extensions; | ||
using NewPlatform.Flexberry.ORM.ODataServiceCore.Common.Exceptions; | ||
using NewPlatform.Flexberry.ORM.ODataServiceCore.Extensions; | ||
using NewPlatform.Flexberry.ORM.ODataServiceCore.Extensions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В этом файле точно все добавленные юзинги нужны?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
No description provided.