-
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?
Changes from 5 commits
20c2596
e98f96a
961acfb
8ed8b3d
69973bf
dbe76d4
cebb4eb
9866616
a18a1ed
89bc458
18a9037
e4dbd5d
5d6d471
77158d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,17 +16,21 @@ namespace ODataServiceSample.AspNetCore | |
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using NewPlatform.Flexberry; | ||
using NewPlatform.Flexberry.Caching; | ||
using NewPlatform.Flexberry.ORM.CurrentUserService; | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
using NewPlatform.Flexberry.Reports.ExportToExcel; | ||
using NewPlatform.Flexberry.Security; | ||
using NewPlatform.Flexberry.Services; | ||
using Unity; | ||
using Unity.Injection; | ||
using LockService = NewPlatform.Flexberry.Services.LockService; | ||
using LockService = NewPlatform.Flexberry.Services.LockService; | ||
|
||
public class Startup | ||
{ | ||
|
@@ -49,7 +53,10 @@ public Startup(IConfiguration configuration) | |
/// <param name="unityContainer">Unity container.</param> | ||
public virtual void ConfigureContainer(IUnityContainer unityContainer) | ||
{ | ||
// Configure Flexberry services via Unity. | ||
// Base dependencies registration. | ||
UnityContainerRegistrations.Registration(unityContainer); | ||
|
||
// Configure Flexberry services via Unity. | ||
var securityManager = new EmptySecurityManager(); | ||
Mock<IAuditService> mockAuditService = new Mock<IAuditService>(); | ||
IBusinessServerProvider businessServerProvider = unityContainer.Resolve<IBusinessServerProvider>(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
namespace NewPlatform.Flexberry.ORM.ODataService.Tests | ||
{ | ||
using ICSSoft.STORMNET.Business; | ||
using ICSSoft.STORMNET.Business.Audit; | ||
using ICSSoft.STORMNET.Business.Interfaces; | ||
using ICSSoft.STORMNET.Security; | ||
using Microsoft.AspNetCore.Http; | ||
using NewPlatform.Flexberry.Caching; | ||
using NewPlatform.Flexberry.ORM.CurrentUserService; | ||
using NewPlatform.Flexberry.ORM.ODataService.Tests.CRUD.Read.Excel; | ||
using NewPlatform.Flexberry.ORM.ODataService.Tests.Http; | ||
using NewPlatform.Flexberry.Reports.ExportToExcel; | ||
using NewPlatform.Flexberry.Security; | ||
using System.Web; | ||
using Unity; | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
/// Created to eliminate code duplication for different dotnet versions. | ||
/// </summary> | ||
public static class UnityContainerRegistrations | ||
{ | ||
/// <summary> | ||
/// 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
{ | ||
unityContainer.RegisterType<IHttpContextAccessor, HttpContextAccessor>(); | ||
#if NETFRAMEWORK | ||
unityContainer.RegisterType<ICurrentUser, WebHttpUser>( | ||
new InjectionConstructor(unityContainer.Resolve<IHttpContextAccessor>())); | ||
#endif | ||
#if NETCOREAPP | ||
unityContainer.RegisterType<ICurrentUser, WebHttpUser>(); | ||
#endif | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
unityContainer.RegisterSingleton<IODataExportService, ExportExcel>(); | ||
unityContainer.RegisterSingleton<ISpreadsheetCustomizer, SpreadsheetCustomizer>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
unityContainer.RegisterSingleton<IConfigResolver, ConfigResolver>(); | ||
|
||
unityContainer.RegisterSingleton<ICacheService, MemoryCacheService>( | ||
new InjectionConstructor("defaultCacheForApplication", 3600)); | ||
|
||
unityContainer.RegisterSingleton<ISecurityManager, EmptySecurityManager>("securityManagerWithoutRightsCheck"); | ||
|
||
unityContainer.RegisterSingleton<IDataService, MSSQLDataService>( | ||
"dataServiceForAuditAgentManagerAdapter", | ||
new InjectionConstructor( | ||
unityContainer.Resolve<ISecurityManager>("securityManagerWithoutRightsCheck"), | ||
unityContainer.Resolve<IAuditService>(), | ||
unityContainer.Resolve<IBusinessServerProvider>()), | ||
new InjectionProperty(nameof(MSSQLDataService.CustomizationStringName), "DefConnStr")); | ||
|
||
unityContainer.RegisterType<IDataService, MSSQLDataService>( | ||
"dataServiceForSecurityManager", | ||
new InjectionConstructor( | ||
unityContainer.Resolve<ISecurityManager>("securityManagerWithoutRightsCheck"), | ||
unityContainer.Resolve<IAuditService>(), | ||
unityContainer.Resolve<IBusinessServerProvider>()), | ||
Inject.Property(nameof(MSSQLDataService.CustomizationStringName), "DefConnStr")); | ||
|
||
unityContainer.RegisterSingleton<ICacheService, MemoryCacheService>( | ||
"cacheServiceForSecurityManager", | ||
new InjectionConstructor("cacheForSecurityManager")); | ||
|
||
unityContainer.RegisterSingleton<ICacheService, MemoryCacheService>( | ||
"cacheServiceForAgentManager", new InjectionConstructor("cacheForAgentManager")); | ||
|
||
unityContainer.RegisterSingleton<ISecurityManager, SecurityManager>( | ||
new InjectionConstructor( | ||
unityContainer.Resolve<IDataService>("dataServiceForSecurityManager"), | ||
unityContainer.Resolve<ICacheService>("cacheServiceForSecurityManager"))); | ||
|
||
unityContainer.RegisterSingleton<IAgentManager, AgentManager>( | ||
new InjectionConstructor( | ||
unityContainer.Resolve<IDataService>("dataServiceForSecurityManager"), | ||
unityContainer.Resolve<ICacheService>("cacheServiceForSecurityManager"))); | ||
|
||
unityContainer.RegisterSingleton<IPasswordHasher, Sha1PasswordHasher>(); | ||
} | ||
} | ||
} |
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