在 castle.windsor 中注册 windows 表格
register windows form in castle.windsor
我在 windows 表单中使用 telerik
,所以我想在 castle.windsor
中注册 windows 表单,但是 windows 表单继承自 Telerik.WinControls.UI.RadForm
我无法注册此表格。
当我的表单继承自 "Form" 然后我不使用 telerik 时,此表单已成功注册。
此代码注册成功
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var container = Bootstrapper.WireUp();//return windsoerContainer
container.Register(Classes.FromAssemblyContaining<Form1>()
.BasedOn<Form>().LifestyleTransient());
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(container.Resolve<Form1>());
}
}
此代码无效
enter code here
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var container = Bootstrapper.WireUp();//return windsoerContainer
container.Register(Classes.FromAssemblyContaining<FrmLogin>()
.BasedOn<RadForm>().LifestyleTransient());
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(container.Resolve<FrmLogin>());
}
}
public partial class FrmLogin : Telerik.WinControls.UI.RadForm//frm login
{
private readonly ICategoryService _categoryService;
public FrmLogin(ICategoryService categoryService)
{
_categoryService = categoryService;
InitializeComponent();
}
}
public static class Bootstrapper
{
public static IWindsorContainer WireUp()
{
var container = new WindsorContainer();
container.Register(Component.For<TransactionInterceptor>().LifestylePerWebRequest());
container.Register(Classes.FromAssemblyContaining<CategoryService>()
.BasedOn<IService>()
.WithServiceFromInterface()
.LifestylePerWebRequest().Configure(a=>a.Interceptors<TransactionInterceptor>()));
container.Register(Classes.FromAssemblyContaining<CategoryRepository>()
.BasedOn<IRepository>()
.WithServiceFromInterface()
.LifestylePerWebRequest());
container.Register(Component.For<IUnitOfWork>().ImplementedBy<EfUnitOfWork>().LifestylePerWebRequest());
container.Register(Component.For<CrmDbContext>().LifestylePerWebRequest());
ServiceLocator.SetCurrent(new WindsorServiceLocator(container));
return container;
}
}
谢谢你帮助我...
解决这个问题就够了
**
.LifestyleSingleton()
**
var container = Bootstrapper.WireUp();//return windsoerContainer
container.Register(Classes.FromAssemblyContaining<FrmLogin>()
.BasedOn<RadForm>().LifestyleSingleton());
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(container.Resolve<FrmLogin>());
我在 windows 表单中使用 telerik
,所以我想在 castle.windsor
中注册 windows 表单,但是 windows 表单继承自 Telerik.WinControls.UI.RadForm
我无法注册此表格。
当我的表单继承自 "Form" 然后我不使用 telerik 时,此表单已成功注册。
此代码注册成功
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var container = Bootstrapper.WireUp();//return windsoerContainer
container.Register(Classes.FromAssemblyContaining<Form1>()
.BasedOn<Form>().LifestyleTransient());
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(container.Resolve<Form1>());
}
}
此代码无效
enter code here
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var container = Bootstrapper.WireUp();//return windsoerContainer
container.Register(Classes.FromAssemblyContaining<FrmLogin>()
.BasedOn<RadForm>().LifestyleTransient());
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(container.Resolve<FrmLogin>());
}
}
public partial class FrmLogin : Telerik.WinControls.UI.RadForm//frm login
{
private readonly ICategoryService _categoryService;
public FrmLogin(ICategoryService categoryService)
{
_categoryService = categoryService;
InitializeComponent();
}
}
public static class Bootstrapper
{
public static IWindsorContainer WireUp()
{
var container = new WindsorContainer();
container.Register(Component.For<TransactionInterceptor>().LifestylePerWebRequest());
container.Register(Classes.FromAssemblyContaining<CategoryService>()
.BasedOn<IService>()
.WithServiceFromInterface()
.LifestylePerWebRequest().Configure(a=>a.Interceptors<TransactionInterceptor>()));
container.Register(Classes.FromAssemblyContaining<CategoryRepository>()
.BasedOn<IRepository>()
.WithServiceFromInterface()
.LifestylePerWebRequest());
container.Register(Component.For<IUnitOfWork>().ImplementedBy<EfUnitOfWork>().LifestylePerWebRequest());
container.Register(Component.For<CrmDbContext>().LifestylePerWebRequest());
ServiceLocator.SetCurrent(new WindsorServiceLocator(container));
return container;
}
}
谢谢你帮助我...
解决这个问题就够了 **
.LifestyleSingleton()
**
var container = Bootstrapper.WireUp();//return windsoerContainer
container.Register(Classes.FromAssemblyContaining<FrmLogin>()
.BasedOn<RadForm>().LifestyleSingleton());
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(container.Resolve<FrmLogin>());