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

Register unity without config file #286

Open
wants to merge 14 commits into
base: feature-239-use-proper-di
Choose a base branch
from

Conversation

torres6093
Copy link

No description provided.

@@ -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>();
Copy link
Contributor

@Anisimova2020 Anisimova2020 Jun 8, 2023

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.

@@ -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" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно стараться избегать несодержательные правки.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@Anisimova2020 Anisimova2020 self-assigned this Jun 26, 2023
namespace NewPlatform.Flexberry.ORM.ODataService.Tests
{
using System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для чего здесь юзинги добавлены?

Copy link
Author

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.
Copy link
Contributor

@Anisimova2020 Anisimova2020 Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мне кажется, что в комментариях нужно сделать акцент, что это просто вспомогательный класс для тестов.

Также добавь в комментарии, что при удалении UnityConfigResolver для версии под дотнет 4.5 нужно определить нужность данного класса (пока что перерегистрировать нужно именно из-за него). Также упоминание "UnityConfigResolver" требуется, чтобы при удалении этого класса поиском наткнулись на это примечание.

Copy link
Author

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Разве это не регистрация изначально закомментированного кода?

"
"

Copy link
Author

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>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично.

Copy link
Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пожалуй, стоит ещё отметить, какой код можно сделать только кодом, а какой и кодом и конфигом. Например, сначала тот, что и там и там, отметив комментарием. А потом тот, что только кодом теперь.

Copy link
Author

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 />
Copy link
Contributor

@Anisimova2020 Anisimova2020 Jun 26, 2023

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 как фабрика. Это тоже хороший вариант, о котором нужно мне сказать.

Copy link
Author

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
Copy link
Contributor

@Anisimova2020 Anisimova2020 Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужны комментарии к классу тестов.

Copy link
Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

После System-юзингов желательно пустую строчку.

Copy link
Author

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Стоит добавить комментарий, в каком случае может потребоваться создавать контейнер прямо здесь.

Copy link
Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В этом файле точно все добавленные юзинги нужны?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants