日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#.NET编程----Spring.NET NHibernate整合(一)

發(fā)布時間:2025/3/15 C# 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#.NET编程----Spring.NET NHibernate整合(一) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


第一個
Spring.NET的程序


?建立項目

項目名稱為:SpringSample,NameSpace為“OKEC.Sample.Spring”。

?添加HelloTest類

HelloTest.cs

using?System;
namespace?OKEC.Sample.Spring
{
????
///?<summary>
????
///?HelloTest?的摘要說明。
????
///?</summary>
????public?class?HelloTest
????{
????????
public?HelloTest()
????????{
????????????
//
????????????
//?TODO:?在此處添加構(gòu)造函數(shù)邏輯
????????????
//
????????}
????????
public?void?Test()
????????{
????????????Console.WriteLine(
"This?is?Spring.NET?Sample?Test!");
????????????Console.WriteLine(
"Please?press?Enter?close?the?windows!");
????????????Console.ReadLine();
//讓程序停留,回車關(guān)閉。
????????}
????}
}



添加Spring.NET的配置文件

文件名:Spring_bean.xml,屬性設(shè)置為:嵌入的資源/ Embedded Resource
<?xml?version="1.0"?encoding="utf-8"?>
<objects?xmlns="http://www.springframework.net"?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?
?????????xsi:schemaLocation
="http://www.springframework.net?
?????????http://www.springframework.net/xsd/spring-objects.xsd">
??<object?id="Hello"?type="OKEC.Sample.Spring.HelloTest,SpringSample"?/>
</objects>



建立Spring.NET的容器初始化對像

SpringContext.cs
using?System;
using?Spring.Core;
using?Spring.Aop;
using?System;
using?Spring.Core;
using?Spring.Aop;
using?Spring.Context;
using?Spring.Context.Support;
namespace?OKEC.Sample.Spring
{
????
///?<summary>
????
///?SpringFactory?的摘要說明。
????
///?</summary>
????public?class?SpringContext
????{
????????
public?SpringContext()
????????{
????????????
//
????????????
//?TODO:?在此處添加構(gòu)造函數(shù)邏輯
????????????
//
????????}
????????
private?static?bool?isInit?=?false;
????????
private?static?IApplicationContext?context;
????????
public?static?void?init()
????????{
????????????
string[]?xmlFiles?=?new?string[1];????????????
????????????xmlFiles[
0]?=?"assembly://SpringSample/OKEC.Sample.Spring/Spring_bean.xml";
????????????context?
=?new?XmlApplicationContext(xmlFiles);
????????????isInit?
=?true;
????????}
????????
public?static?IApplicationContext?Context
????????{
????????????
get{
????????????????
if(!isInit)
????????????????{
????????????????????init();
????????????????}
????????????????
return?context;
????????????}
????????}
????}
}



添加啟動程序

StartMain.cs
using?System;
namespace?OKEC.Sample.Spring
{
????
///?<summary>
????
///?StartMain?的摘要說明。
????
///?</summary>
????public?class?StartMain
????{
????????
public?StartMain()
????????{
????????????
//
????????????
//?TODO:?在此處添加構(gòu)造函數(shù)邏輯
????????????
//
????????}
????????[STAThread]
????????
static?void?Main()?
????????{
????????????
//Startup?Spring?Content
????????????SpringContext.init();

????????????
//Test?Spring?IOC
????????????HelloTest?test?=?(HelloTest)SpringContext.Context.GetObject("Hello");
????????????test.Test();
????????}
????}
}



運(yùn)行程序

結(jié)果為:

This?is?Spring.NET?Sample?Test!
Please?press?Enter?close?the?windows
!


你的第一個Spring.NET的程序成功了!



文檔中的項目源代碼請從以下地址下載:
http://www.springframework.cn/read.php?fid=8&tid=2&toread=1
完整的文檔請下載PDF文檔:
http://www.springframework.cn/read.php?fid=2&tid=1&toread=1

轉(zhuǎn)載于:https://www.cnblogs.com/it1630/archive/2006/12/01/579059.html

新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎!定制產(chǎn)品紅包拿不停!

總結(jié)

以上是生活随笔為你收集整理的C#.NET编程----Spring.NET NHibernate整合(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。