我有我的工作单元类,它具有NHibernate ISession的依赖性和相同的ISession我希望使用Unity DI xml配置传递我的存储库。
UnitOfWork课程:
import java.awt.Color;
import java.time.DayOfWeek;
import java.time.LocalDate;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class CalendarTest {
JFrame f;
JLabel monthYearLbl;
JLabel[] dayLbl,dateLbl;
JPanel monthAndYear,dayAndDate;
LocalDate ld;
String month,year,day;
//constructor
public CalendarTest(){
f = new JFrame("Calender");
f.setSize(365,250);
f.setLayout(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public void showMonthAndYear(){
monthAndYear = new JPanel();
monthAndYear.setBounds(0,0,350,25);
f.add(monthAndYear);
monthAndYear.setBackground(Color.MAGENTA);
ld = LocalDate.now();
month = String.valueOf(ld.getMonth());
year = String.valueOf(ld.getYear());
monthYearLbl = new JLabel(month+"-"+year);
monthAndYear.add(monthYearLbl);
}
public void showDayAndDate(){
dayAndDate = new JPanel();
dayAndDate.setLayout(null);
dayAndDate.setBounds(0,27,350,185);
f.add(dayAndDate);
dayAndDate.setBackground(Color.cyan);
//getting the first day name of the current month
DayOfWeek dow = LocalDate.of(ld.getYear(),ld.getMonth(),1).getDayOfWeek();
int lengthOfMonth = LocalDate.of(ld.getYear(),ld.getMonth(),1).lengthOfMonth();
int friday=0;
dayLbl = new JLabel[8];
int xCord = 10;
for(int i=0;i<7;i++){
String s = String.valueOf(dow);//converting dow object to string
String formatedDay = String.format("%.3s",s);//formating day in short form
if(formatedDay== "FRI"){
friday = i;
}
dayLbl[i] = new JLabel(formatedDay);//creating jlabel
dow = dow.plus(1);//incrementing day name
dayLbl[i].setBounds(xCord,10,30,20);
dayAndDate.add(dayLbl[i]);
xCord = xCord+50;//dynamic positioning of day name
}
dateLbl = new JLabel[35];
int index = 1,ycord=35;
//loop for showing the date from 1 to endofmonth
for(int i=1;i<=5;i++){
int xcord = 15;
for(int j=0;j<7;j++){
dateLbl[index] = new JLabel(String.valueOf(index));
dateLbl[index].setBounds(xcord,ycord,20,20);
if(j==friday){
dateLbl[index].setBackground(Color.black);//indicating holiday
}
dayAndDate.add(dateLbl[index]);
xcord = xcord+50;
if(index==lengthOfMonth){
break;
}
index++;
f.add(dayAndDate);
}
ycord = ycord+25;
}
}
public static void main(String[] args) {
CalendarTest calendar = new CalendarTest();
calendar.showMonthAndYear();
calendar.showDayAndDate();
}
存储库类:
public class UnitOfWork : IUnitOfWork
{
private ISession _session;
public UnitOfWork(ISession session)
{
_session = session; // This same session I want to pass to my repository using Unity DI xml configuration.
}
}
请告诉我如何使用基于Unity DI xml的配置实现此目的。