Add project files.
This commit is contained in:
9
DIDemoLib/DIDemoLib.csproj
Normal file
9
DIDemoLib/DIDemoLib.csproj
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
8
DIDemoLib/IMessages.cs
Normal file
8
DIDemoLib/IMessages.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace DIDemoLib
|
||||||
|
{
|
||||||
|
public interface IMessages
|
||||||
|
{
|
||||||
|
string SayGoodBye();
|
||||||
|
string SayHello();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
DIDemoLib/Messages.cs
Normal file
14
DIDemoLib/Messages.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DIDemoLib
|
||||||
|
{
|
||||||
|
public class Messages : IMessages
|
||||||
|
{
|
||||||
|
public string SayHello() => "Hello Viewer";
|
||||||
|
public string SayGoodBye() => "Goodbye, farewell and good day!";
|
||||||
|
}
|
||||||
|
}
|
||||||
26
WinFormDi/ContainerConfig.cs
Normal file
26
WinFormDi/ContainerConfig.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using DIDemoLib;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormDi
|
||||||
|
{
|
||||||
|
public static class ContainerConfig
|
||||||
|
{
|
||||||
|
public static IHost? Configure()
|
||||||
|
{
|
||||||
|
var builder = new HostBuilder()
|
||||||
|
.ConfigureServices((_, services) =>
|
||||||
|
{
|
||||||
|
services
|
||||||
|
.AddTransient<IMessages, Messages>()
|
||||||
|
.AddTransient<MainWindow>();
|
||||||
|
});
|
||||||
|
return builder.Build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
75
WinFormDi/MainWindow.Designer.cs
generated
Normal file
75
WinFormDi/MainWindow.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
namespace WinFormDi
|
||||||
|
{
|
||||||
|
partial class MainWindow
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
helloText = new Label();
|
||||||
|
goodbyeText = new Label();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// helloText
|
||||||
|
//
|
||||||
|
helloText.AutoSize = true;
|
||||||
|
helloText.Font = new Font("Segoe UI", 20.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
helloText.Location = new Point(45, 55);
|
||||||
|
helloText.Name = "helloText";
|
||||||
|
helloText.Size = new Size(83, 37);
|
||||||
|
helloText.TabIndex = 0;
|
||||||
|
helloText.Text = "------";
|
||||||
|
//
|
||||||
|
// goodbyeText
|
||||||
|
//
|
||||||
|
goodbyeText.AutoSize = true;
|
||||||
|
goodbyeText.Font = new Font("Segoe UI", 20.25F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
goodbyeText.Location = new Point(45, 129);
|
||||||
|
goodbyeText.Name = "goodbyeText";
|
||||||
|
goodbyeText.Size = new Size(83, 37);
|
||||||
|
goodbyeText.TabIndex = 1;
|
||||||
|
goodbyeText.Text = "------";
|
||||||
|
//
|
||||||
|
// MainWindow
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(goodbyeText);
|
||||||
|
Controls.Add(helloText);
|
||||||
|
Name = "MainWindow";
|
||||||
|
Text = "MainWindow";
|
||||||
|
FormClosing += MainWindow_FormClosing;
|
||||||
|
Load += MainWindow_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label helloText;
|
||||||
|
private Label goodbyeText;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
WinFormDi/MainWindow.cs
Normal file
35
WinFormDi/MainWindow.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using DIDemoLib;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace WinFormDi
|
||||||
|
{
|
||||||
|
public partial class MainWindow : Form
|
||||||
|
{
|
||||||
|
private readonly IMessages _messages;
|
||||||
|
|
||||||
|
public MainWindow(IMessages messages)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_messages = messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
helloText.Text= _messages.SayHello();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
goodbyeText.Text= _messages.SayGoodBye();
|
||||||
|
MessageBox.Show("Closing...", "Warning", MessageBoxButtons.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
120
WinFormDi/MainWindow.resx
Normal file
120
WinFormDi/MainWindow.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
||||||
36
WinFormDi/Program.cs
Normal file
36
WinFormDi/Program.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using DIDemoLib;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
namespace WinFormDi
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
var host = ContainerConfig.Configure();
|
||||||
|
using var scope = host.Services.CreateScope();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var services = scope.ServiceProvider;
|
||||||
|
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||||
|
|
||||||
|
var frm = services.GetRequiredService<MainWindow>();
|
||||||
|
Application.Run(frm);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"An error has occured: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
WinFormDi/WinFormDi.csproj
Normal file
20
WinFormDi/WinFormDi.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net7.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DIDemoLib\DIDemoLib.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
31
WinFormDiApp.sln
Normal file
31
WinFormDiApp.sln
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.6.33829.357
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormDi", "WinFormDi\WinFormDi.csproj", "{940A0A13-2195-47DD-9FDE-16A0C57AF3BF}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DIDemoLib", "DIDemoLib\DIDemoLib.csproj", "{839E6DE6-4644-4279-A7B1-449BD63897A3}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{940A0A13-2195-47DD-9FDE-16A0C57AF3BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{940A0A13-2195-47DD-9FDE-16A0C57AF3BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{940A0A13-2195-47DD-9FDE-16A0C57AF3BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{940A0A13-2195-47DD-9FDE-16A0C57AF3BF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{839E6DE6-4644-4279-A7B1-449BD63897A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{839E6DE6-4644-4279-A7B1-449BD63897A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{839E6DE6-4644-4279-A7B1-449BD63897A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{839E6DE6-4644-4279-A7B1-449BD63897A3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {E1B6FC55-3F9C-40C2-975E-3D08DF8A32AA}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user