开发者

StructureMap with my own attributes in C#

开发者 https://www.devze.com 2022-12-25 09:40 出处:网络
I have an attribute that I have written that has a dependency on the Data Access Layer so I made a constructor that took the DAL class as a parameter (marked wit开发者_开发知识库h [DefaultConstructor]

I have an attribute that I have written that has a dependency on the Data Access Layer so I made a constructor that took the DAL class as a parameter (marked wit开发者_开发知识库h [DefaultConstructor] and another, blank, constructor that is parameterless. When I call a method that depends on the attribute how do I make StructureMap inject the correct type?

Thanks

Gareth


I have been working on the same problem, i'm using something like this:

ObjectFactory.Initialize(x =>
{
    x.PullConfigurationFromAppConfig = true;
    x.SetAllProperties(p => p.TypeMatches(t => 
        t.GetCustomAttributes(typeof(InjectAttribute), true).Length > 0));
}       

I am having some issues injecting onto webform pages but it works when creating instances using ObjectFactory...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号