Добавил юнити контейнер

This commit is contained in:
gg12 darfren 2024-05-21 19:28:42 +04:00
parent 42a674631d
commit b5ae809fc2
5 changed files with 51 additions and 3 deletions

View File

@ -49,7 +49,7 @@
ClientSize = new Size(800, 450); ClientSize = new Size(800, 450);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Name = "ViewMailForm"; Name = "ViewMailForm";
Text = "ViewMailForm"; Text = "Просмотр почты";
Load += ViewMailForm_Load; Load += ViewMailForm_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);

File diff suppressed because one or more lines are too long

View File

@ -14,7 +14,7 @@ namespace IceCreamShopContracts.DI
private static readonly object _locjObject = new(); private static readonly object _locjObject = new();
private DependencyManager() private DependencyManager()
{ {
_dependencyManager = new ServiceDependencyContainer(); _dependencyManager = new UnityDependencyContainer();
} }
public static DependencyManager Instance public static DependencyManager Instance
{ {

View File

@ -0,0 +1,39 @@
using IceCreamShopContracts.DI;
using Microsoft.Extensions.Logging;
using Unity;
using Unity.Microsoft.Logging;
namespace IceCreamShopContracts.DI
{
public class UnityDependencyContainer : IDependencyContainer
{
private readonly IUnityContainer _container;
public UnityDependencyContainer()
{
_container = new UnityContainer();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
var factory = LoggerFactory.Create(configure);
_container.AddExtension(new LoggingExtension(factory));
}
public void RegisterType<T>(bool isSingle) where T : class
{
_container.RegisterType<T>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
public T Resolve<T>()
{
return _container.Resolve<T>();
}
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
{
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
}
}

View File

@ -8,6 +8,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Container" Version="5.11.11" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>