在castle.windsor中注册窗体

时间:2017-11-25 12:37:10

标签: c# telerik castle

我在Windows窗体中使用telerik,所以我想在castle.windsor中注册窗体,但是从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;
    }
}

感谢您帮助我...

1 个答案:

答案 0 :(得分:0)

解决这个问题就足够了 **

  

.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>());
相关问题